Windows Vista access denied using wmi

  • Thread starter Thread starter rac8006
  • Start date Start date
R

rac8006

Guest
I new to vbscript programming. I have the following script that works fine
in XP but fails in Vista home premium. It get access denied (return code 2)
for the system processes. It won't print the owner or commandline for systems
processes. I'm looged in with admin priv's on both os's. Any ideas whats
wrong?

Thanks

strComputer = "."
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'==============================================================
Const Data_Path = "C:\temp\"
Const fileName = "process.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(Data_Path & filename) Then
Set f = fso.OpenTextFile(Data_Path & fileName,2, True)
Else
Set f = fso.OpenTextFile(Data_Path & fileName,8)
End If
strComputer = "."
Set colProcesses = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & _
"\root\cimv2").ExecQuery("Select * from Win32_Process")
For Each objProcess in colProcesses
Return = objProcess.GetOwner(strNameOfUser)
f.WriteLine Return & vbTab & objProcess.Name & vbTab & StrNameOfUser& vbTab
& objProcess.CommandLine
Next
 
Re: access denied using wmi

rac8006 wrote:
> I new to vbscript programming. I have the following script that works fine
> in XP but fails in Vista home premium. It get access denied (return code 2)
> for the system processes. It won't print the owner or commandline for systems
> processes. I'm looged in with admin priv's on both os's. Any ideas whats
> wrong?
>
> Thanks
>
> strComputer = "."
> Const ForReading = 1
> Const ForWriting = 2
> Const ForAppending = 8
> '==============================================================
> Const Data_Path = "C:\temp\"
> Const fileName = "process.txt"
> Set fso = CreateObject("Scripting.FileSystemObject")
> If Not FSO.FileExists(Data_Path & filename) Then
> Set f = fso.OpenTextFile(Data_Path & fileName,2, True)
> Else
> Set f = fso.OpenTextFile(Data_Path & fileName,8)
> End If
> strComputer = "."
> Set colProcesses = GetObject("winmgmts:" & _
> "{impersonationLevel=impersonate}!\\" & strComputer & _
> "\root\cimv2").ExecQuery("Select * from Win32_Process")
> For Each objProcess in colProcesses
> Return = objProcess.GetOwner(strNameOfUser)
> f.WriteLine Return & vbTab & objProcess.Name & vbTab & StrNameOfUser& vbTab
> & objProcess.CommandLine
> Next

Right click on it and select "run as administrator"
 
Back
Top