Sign in to follow this  
Followers 0
SergeiK

RunAs issue

6 posts in this topic

Hello Experts,

I have made 2 scripts to run my microsoft c# application on user's logon to collect some data. It works fine, when an administrator logs on to a PC, but when I try to start the HistoryLogonLauncher.exe by RunAs function with a service admin account - it does not work. I need your urgent assistance, please. Thank you very much!

IfAdmin.exe (AutoIT)

[/size][/size]
[size=2]$Path = @LogonServer & "\NETLOGON\Workstation\HL\HistoryLogonLauncher.exe" ; Path to the AutoIT executable[/size]
[size=2]If IsAdmin () Then
If FileExists ($Path) Then
  RunWait ($Path)
Else
  Exit
EndIf[/size]
[size=2]Else
AdminHLL ()
EndIf[/size]
[size=2]Func AdminHLL () ; This function runs HistoryLogonLauncher.exe under[/size]
[size=2]If FileExists ($Path) Then
RunAsWait ("admin",@LogonDomain,"p@$$w0rd",2,$Path)
Else
Exit
EndIf
EndFunc

HistoryLogonLauncher.exe (AutoIT)

[/size]
If @OSVersion = "win_7" or @OSVersion = "win_xp" or @OSVersion = "win_xpe" or @OSVersion = "win_vista" or @OSVersion = "win_2000" Then
Virt()
Else
Exit
EndIf[/size]
[size=2]Func Virt ()
$objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2")
$objItems = $objWMI.ExecQuery("Select * from Win32_ComputerSystemProduct", "WQL", 0x10 + 0x20)
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
If IsObj($objItems) Then
   For $objItem In $objItems[/size]
[size=2]    If $objItem.Name <> "VMware Virtual Platform" or "Virtual Machine" Then[/size]
[size=2]  HL_copying ()[/size]
[size=2]Else
Exit[/size]
[size=2]EndIf
Next
EndIf
EndFunc[/size]
[size=2]Func HL_copying ()[/size]
[size=2]If FileExists (@LogonServer & "\NETLOGON\Workstation\HL\HistoryLogon.exe") Then
  FileCopy (@LogonServer & "\NETLOGON\Workstation\HL\HistoryLogon.exe", @WindowsDir & "\Temp\",1)
  HistoryLogonRun ()[/size]
[size=2]  Else
  Exit
EndIf[/size]
[size=2]EndFunc[/size]
[size=2]Func HistoryLogonRun ()[/size]
[size=2]  If FileExists (@WindowsDir & "\Temp\HistoryLogon.exe") Then
   Run (@WindowsDir & "\Temp\HistoryLogon.exe")
  Else
  Exit
  EndIf
EndFunc

Share this post


Link to post
Share on other sites



That script has all kinds of non-autoit code added I have no clue why it is there like and . When you run a program under the system service area, you will not see any interface by default. It cannot interact with the users desktop unless certain things are done to make that possible.

Share this post


Link to post
Share on other sites

Hello Morthawt,

I republished the code - please, kindly advise how to make it correctly...

IfAdmin.exe

$Path = @LogonServer & "\NETLOGON\Workstation\HL\HistoryLogonLauncher.exe" ; Path to the AutoIT executable
If IsAdmin () Then
If FileExists ($Path) Then
  RunWait ($Path)
Else
  Exit
EndIf
Else
AdminHLL ()
EndIf
Func AdminHLL () ; This function runs HistoryLogonLauncher.exe under
If FileExists ($Path) Then
RunAsWait ("admin",@LogonDomain,"p@$$w0rd",2,$Path)
Else
Exit
EndIf
EndFunc

HistoryLogonLauncher.exe

If @OSVersion = "win_7" or @OSVersion = "win_xp" or @OSVersion = "win_xpe" or @OSVersion = "win_vista" or @OSVersion = "win_2000" Then
HL_copying ()
Else
Exit
EndIf
Func Virt ()
$objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2")
$objItems = $objWMI.ExecQuery("Select * from Win32_ComputerSystemProduct", "WQL", 0x10 + 0x20)
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
If IsObj($objItems) Then
   For $objItem In $objItems
    If $objItem.Name <> "VMware Virtual Platform" or "Virtual Machine" Then
  HL_copying ()
Else
Exit
EndIf
Next
EndIf
EndFunc
 
Func HL_copying ()
If FileExists (@LogonServer & "\NETLOGON\Workstation\HL\HistoryLogon.exe") Then
  FileCopy (@LogonServer & "\NETLOGON\Workstation\HL\HistoryLogon.exe", @WindowsDir & "\Temp\",1)
  HistoryLogonRun ()
  Else
  Exit
EndIf
EndFunc
Func HistoryLogonRun ()
  If FileExists (@WindowsDir & "\Temp\HistoryLogon.exe") Then
   Run (@WindowsDir & "\Temp\HistoryLogon.exe")
  Else
  Exit
  EndIf
EndFunc

Share this post


Link to post
Share on other sites

First, you never said whether the script works at all. Does any of it work for you? Is only part of it not working? If so, which part?

Second, I notice in the HistoryLogonLauncher.exe, you never call the Virt() function or the HL_copying() function. Therefore, those functions will not run at all.


#include <ByteMe.au3>

Share this post


Link to post
Share on other sites

I am sorry, I have changed the original script by some reason :graduated: - now it should be fine! And it works fine, if I logon with admin account and run it...

If @OSVersion = "win_7" or @OSVersion = "win_xp" or @OSVersion = "win_xpe" or @OSVersion = "win_vista" or @OSVersion = "win_2000" Then
Virt ()
Else
Exit
EndIf
Func Virt ()
$objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2")
$objItems = $objWMI.ExecQuery("Select * from Win32_ComputerSystemProduct", "WQL", 0x10 + 0x20)
$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
If IsObj($objItems) Then
   For $objItem In $objItems
    If $objItem.Name <> "VMware Virtual Platform" or "Virtual Machine" Then
  HL_copying ()
Else
Exit
EndIf
Next
EndIf
EndFunc
 
Func HL_copying ()
If FileExists (@LogonServer & "\NETLOGON\Workstation\HL\HistoryLogon.exe") Then
  FileCopy (@LogonServer & "\NETLOGON\Workstation\HL\HistoryLogon.exe", @WindowsDir & "\Temp\",1)
  HistoryLogonRun ()
  Else
  Exit
EndIf
EndFunc
Func HistoryLogonRun ()
  If FileExists (@WindowsDir & "\Temp\HistoryLogon.exe") Then
   Run (@WindowsDir & "\Temp\HistoryLogon.exe")
  Else
  Exit
  EndIf
EndFunc

Share this post


Link to post
Share on other sites

Hi,

I have worked around the issue myselft. The problem was with windows variables when you use runas -there were unavailable...and impersonate level in wmi query...

Cheers,

Sergei

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0