Hi all!
Need some help with a script that needs to run some part of the code as another user and then start a service as the user executing the script.
Need to run the select query as another user and then start the service as the user executing the script, is this possible?
The user executing this script doesn't have the permission to see all the processes on the server, and i haven't found any solution to give the user permission for that.
Thanks!!
/Johan
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = " & _
"'t1.exe'")
If colProcessList.Count = 0 Then
MsgBox "Terminal is available, press OK to connect", vbOKCancel
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
objWMIService.Create("t1.exe vmrc://10.10.10.10:5900/Terminal1")
Else
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strNameOfUser)
Wscript.Echo "Terminal is used by " & strNameOfUser & "."
Next
End If
'If colProcessList.Count = 0 Then
' Wscript.Echo "Terminal1 is available.
Need some help with a script that needs to run some part of the code as another user and then start a service as the user executing the script.
Need to run the select query as another user and then start the service as the user executing the script, is this possible?
The user executing this script doesn't have the permission to see all the processes on the server, and i haven't found any solution to give the user permission for that.
Thanks!!
/Johan
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = " & _
"'t1.exe'")
If colProcessList.Count = 0 Then
MsgBox "Terminal is available, press OK to connect", vbOKCancel
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2:Win32_Process")
objWMIService.Create("t1.exe vmrc://10.10.10.10:5900/Terminal1")
Else
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strNameOfUser)
Wscript.Echo "Terminal is used by " & strNameOfUser & "."
Next
End If
'If colProcessList.Count = 0 Then
' Wscript.Echo "Terminal1 is available.