Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to run some of the code as another user.

Status
Not open for further replies.

Svanen

Technical User
Dec 15, 2004
10
SE
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top