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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI pagefile check on remote PC fails where local PC works

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
0
0
GB
Hi all - I've got a script that returns various PC details but for some reason the pagefile info isn't retrieved from remote PCs (shows as blank) but is retrieved fine if I enter my own PC as the target. Sometimes remote DNS/IP info is missing aswell but I'm not too worried about those oddities. Eg script below the PC info shows when remote PC is a target but pagefile doesn't - eg ideas?

Code:
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Dim OutputTxt

' Here we initialize the variables for user interaction

Title = "Computer Name"
Message = "Enter Computer name" 

' Ask for Computer name
strComputer = Trim(InputBox(Message,Title,"",5000,5000))

Set objshell = CreateObject("Wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' PC
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
						  wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
	pcmake =		objItem.Manufacturer
	pcmodel =		objItem.Model
	pcname =		objItem.Name
	pctype =		objItem.SystemType
	pcmemory =		objItem.TotalPhysicalMemory
	pcusername =	objItem.UserName
Next
' Pagefile
'set pcpagefile = wmic pagefileset GET maximumsize /value
'pcpagefile = Replace(objitem.MaximumSize,"MaximumSize=","")
set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFile", "WQL", _
						  wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
	pagefilename =	objitem.Name
	pagefilesize1 = objitem.InitialSize
	pagefilesize2 = objitem.MaximumSize
Next

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Remove "On Error Resume Next", and you will likely see an error message that will explain the problem
 
Unfortunately I get no error message - and why I input my PC name the following lines at the end show fine
f1.Writeline("Pagefile: Name: " & pagefilename)
f1.Writeline(" Initial Size: " & FormatNumber(pagefilesize1,0) & " m")
f1.Writeline(" Max Size: " & FormatNumber(pagefilesize2,0) & " m")
But if using a remote PC they will just be blank besides the m's on the end - that's without on error resume next

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Well you may be right in that I was running from a 64bit machine against some 32bits but also against another 64bit, but none of them had results except mine. And the rest of the script which gathers all sorts of hardware info works regardless it seems. So I'm at a loss :|

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Have you verified your security allows it?
Try changing this:
Code:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
To this:
Code:
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Note that for this type of query to work, your account needs to have admin rights to the target system.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
PS: You should also remove the duplicate declaration for objWMIService. You have two lines with the same declaration.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Well spotted, I think that was from where I copied relevant parts to this post. I'll try the impersonate bit tomorrow and see how it goes. I do have admin rights to remote PCs.

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
This simplified test code...
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colPageFiles = objWMIService.ExecQuery("Select * from Win32_PageFile")

For Each objPageFile in colPageFiles
    Wscript.Echo "Creation Date: " & objPageFile.CreationDate
    Wscript.Echo "Description: " & objPageFile.Description
    Wscript.Echo "Drive: " & objPageFile.Drive        
    Wscript.Echo "File Name: " & objPageFile.FileName  
    Wscript.Echo "File Size: " & objPageFile.FileSize  
    Wscript.Echo "Initial Size: " & objPageFile.InitialSize
    Wscript.Echo "Install Date: " & objPageFile.InstallDate
    Wscript.Echo "Maximum Size: " & objPageFile.MaximumSize
    Wscript.Echo "Name: " & objPageFile.Name  
    Wscript.Echo "Path: " & objPageFile.Path  
Next

...returns nothing on my Win7 box (64-bit), including when invoking the script from an elevated command prompt. It does work on XP and a 2003 (also 32-bit) server.
 
guitarzan,

I copied your code without modification and ran it on my work PC (Win 7 x64). Here is the response I get back.

[pre]
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

Creation Date: 20150212143155.381210-420
Description: c:\pagefile.sys
Drive: c:
File Name: pagefile
File Size: 8262492160
Initial Size: 0
Install Date: 20150212143155.381210-420
Maximum Size: 0
Name: C:\pagefile.sys
Path:
***** script completed - exit code: 0 *****
[/pre]

Looks to me like that code is fine and you are dealing with a permissions issue.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Interesting... perhaps it is just a permissions issue that the OP is having after all. I used an elevated command prompt (right-click, Run as Administrator), which usually does the trick when permissions are a problem?
 
When it comes to WMI, UAC elevation is not always sufficient. Your ID still needs to have rights to the WMI database.

Another way to check is to use WBEMTEST which is the built in WMI tool that has been around but hidden since Windows 95.

Run WBEMTEST from the run command.
Click Connect
Click Connect
Click Enum Instances
Type Win32_Pagefile
Click OK
Double click the text in the box

In the center pane you should now see your instances details. Look for the caption or file size properties to ensure you are connected and have access.

You can follow this article to check the security that is set (written for XP but still applies).


I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
I just tried that test code on my home PC win7 64bit and get nothing. And when I run the wbemtest I get nothing in the add/delete/close dialog textarea. That's from elevated command prompt too. Testing my above script parts I also get results but not from the pagefile bit? My work Pc however runs my script fine including the pagefile info - but others I target with it work except for the pagefile info. All in all, this leaves me confused ...

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Mark: I had the same results as Leozack with WBEMTEST (on 2 different Windows 7 64-bit boxes), and I tinkered briefly with the microsoft kb regarding setting permissions, still had no effect and im not going to tinker much more...

But I do appreciate you pointing out WBEMTEST.... i have never used that before!
 
Wish I could help more to isolate the issue. It has to be a permissions thing. That code is both sound and supported on x64.

Guitarzan, WBEMTEST was originally designed to be just used by MS support personnel, then the word got out about it. The interface is really clunky because it was not intended for the masses to use, but it can really come in handy when you need to get info about a system.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
What would you do to use WBEMTEST against a remote PC?

Ok so I've tested more today. It seems with either of these lines
'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
I get the same results - some remote PCs ARE replying with pagefile info, and others aren't. I have a nasty feeling that the ones that are blank have no pagefile (set to 0 in windows) which is why I wanted to include pagefile info in our remote PC details in the first place. Argh ...

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
I can confirm that I remoted onto 1 such PC and sure enough it had 0 pagefile - so I set up a 4g c:\pagefile.sys using regedit and rebooted and now the script returns as expected. So if anyone is having problems there must be something stopping it. The script (cut down to just the pagefile part) is :

Code:
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Dim OutputTxt

' Here we initialize the variables for user interaction

Title = "Computer Name"
Message = "Enter Computer name" 

' Ask for Computer name
strComputer = Trim(InputBox(Message,Title,"",5000,5000))

Set objshell = CreateObject("Wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile(objshell.ExpandEnvironmentStrings("%TEMP%\testfile.txt"), True)

if strcomputer <> "" then
	strTarget = strcomputer 
	Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
	strPingResults = LCase(objExec.StdOut.ReadAll)
	If InStr(strPingResults, "reply from") Then
		' WScript.Echo strTarget & " responded to ping."

		Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
' Pagefile
		set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PageFile", "WQL", _
								  wbemFlagReturnImmediately + wbemFlagForwardOnly)
		For Each objItem In colItems
			pagefilename =	objitem.Name
			pagefilesize1 = objitem.InitialSize
			pagefilesize2 = objitem.MaximumSize
		Next

		'Write output to the text file

		f1.Writeline("PC DETAILS FOR " & pcname)
		f1.Writeline
		f1.Writeline("Pagefile Name:     " & pagefilename)
		f1.Writeline("Pagefile Initial:  " & FormatNumber(pagefilesize1,0) & " m")
		f1.Writeline("Pagefile Max:      " & FormatNumber(pagefilesize2,0) & " m")

		'Display Text file on screen
		objshell.run objshell.ExpandEnvironmentStrings("%TEMP%\testfile.txt")

	Else
		WScript.Echo strTarget & " did not respond to ping."
	End If
End if

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Leozack, WBEMTEST is ONLY for local access. Download a copy of Scriptomatic 2 to query remote systems.

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Check out my scripting solutions at
Work SMARTER not HARDER.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top