×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

WMI pagefile check on remote PC fails where local PC works

WMI pagefile check on remote PC fails where local PC works

WMI pagefile check on remote PC fails where local PC works

(OP)
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 --> vbscript

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); 

RE: WMI pagefile check on remote PC fails where local PC works

Remove "On Error Resume Next", and you will likely see an error message that will explain the problem

RE: WMI pagefile check on remote PC fails where local PC works

(OP)
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); 

RE: WMI pagefile check on remote PC fails where local PC works

In that case, the query is just returning no results. This may have to do with running the script on a 64-bit machine vs 32-bit. I see that Win32_PageFile is deprecated in favor of Win32_PageFileUsage.
http://www.activexperts.com/admin/scripts/wmi/vbsc...

Not sure if this gives the same information though.

RE: WMI pagefile check on remote PC fails where local PC works

(OP)
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); 

RE: WMI pagefile check on remote PC fails where local PC works

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 http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: WMI pagefile check on remote PC fails where local PC works

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 http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: WMI pagefile check on remote PC fails where local PC works

(OP)
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); 

RE: WMI pagefile check on remote PC fails where local PC works

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.

RE: WMI pagefile check on remote PC fails where local PC works

guitarzan,

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

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 *****
 

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 http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: WMI pagefile check on remote PC fails where local PC works

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?

RE: WMI pagefile check on remote PC fails where local PC works

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).
http://support.microsoft.com/kb/295292

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 http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: WMI pagefile check on remote PC fails where local PC works

(OP)
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); 

RE: WMI pagefile check on remote PC fails where local PC works

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!

RE: WMI pagefile check on remote PC fails where local PC works

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 http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

RE: WMI pagefile check on remote PC fails where local PC works

(OP)
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); 

RE: WMI pagefile check on remote PC fails where local PC works

(OP)
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 --> vbscript

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); 

RE: WMI pagefile check on remote PC fails where local PC works

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 http://www.thespidersparlor.com/vbscript

Work SMARTER not HARDER.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close