Im wondering if its posible to detect windows CE in a windows logon script ( Scrip runs in the user account ).
I assume its posible to detect this via some checking for some file, but i was hoping for a bit "cleaner" solution.
You can use the below code to check against the Windows version in VBscript using WMI. Replace the XXXXXXXXX with the appropriate version number.
strComputer = "." 'We are using computer "here"
set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2") 'Initialize WMI object for this computer
'Displays which operating system is installed on the current computer.
set colOperatingSystems = objWMIService.ExecQuery _
("Select Caption, Version from Win32_OperatingSystem") 'Query WMI for OS Version
'Validate that OS version is valid
for each objOperatingSystem in colOperatingSystems ' Parse results
if objOperatingSystem.Version = "XXXXXXXXX" Then
'Do something here
end if
next
If you're not sure what the version is, try changing the if/then statement temporarily to
WScript.Echo objOperatingSystem.Version
and running it manually. That will output the correct version # for your system.
Related
I'm trying to write a script capable of shutting down a local computer even if the computer is locked. I'm trying to invoke the shutdown method of the Win32_OperatingSystem class. I've read this article: http://www.microsoft.com/technet/scriptcenter/guide/sas_cpm_evqo.mspx and it still won't work. I've even tried copying and pasting the code provided in the article. It still won't work. Any idea what might be the issue?
The cause is a syntax error with Set objWMIService = GetObject("winmgmts: {(Shutdown)}" _...
Should be as follows:
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" _
& strComputer & "\root\cimv2")
I have a group of network all connected in LAN and all are in domain. And I have a VB script to get the installed software. I have to run the script on all the systems without user interaction.
If you are using WMIService in vbs, then try below with replacing strComputer in a loop, then another loop for the softwares
Set oWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colSoftware = oWMIService.ExecQuery("Select * from Win32_Product")
But you have to run this with domain admin account or an account that is "Administrators" on all the domain PC.
I have searched the Stack Overflow site for questions related to closing
Outlook. There were a number of hits but none seem to describe what I'm
trying to do.
The problem I'm trying to solve is how to backup the Outlook data base
automatically and unattended. Outlook needs to be closed (if it is
running) before copying the .pst files.
I found a VBScript at (www.howto-outlook.com/howto/closeoutlookscript.htm)
that seems like what I need. But I can't get it to run when initiated from
the Windows Task Scheduler.
I am running on a Windows 8 Sony laptop.
My VBScript should close Outlook prior to doing a backup of the .pst files.
The code is stored in CloseOutlookVerify.vbs.
Below is the offending code from CloseOutlookVerify.vbs:
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Outlook.exe'")
For Each objProcess in colProcessList
Set objOutlook = CreateObject("Outlook.Application")
' The above line fails with ERR = 70 - Permission denied
objOutlook.Quit
Closed = 1
Next
This script works correctly if I double-click on the .vbs file
from Windows Explorer.
It works correctly if I run it from a DOS Command Prompt window.
It fails with err = 70 when run via the Windows Task Scheduler.
So, what is different about running this script from a command prompt
vs. by the task scheduler? And how can I make it work correctly when run
by the task scheduler?
FYI - I made my living programming in C and Unix shell languages, but this
is my first exposure to VBS in the Windows environment.
Many thanks for any expertise you can provide.
I think it is because impersonationLevel has not been set. Try this:
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strSysName & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'Outlook.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
I was pointed in this direction by the author of a script I've been using for a couple of years now.
It allows the remote locking of a desktop, and works fine locally and remotely under Windows XP, and works fine locally under Windows 7, but when trying to use it remotely against a Windows 7 machine it fails to work.
It's been great for a few years now and has been very useful, but we've recently started to deploy Windows 7 machines on site and once the upgrade is fully completed I won't be able to use this anymore.
The same question that I have was posed a couple of years back, but went unanswered.
Here is the VBS code:
' StartProcess.vbs
' Sample VBScript to start a process. Inputbox for name
' Author Guy Thomas http://computerperformance.co.uk/
' Version 2.2 - December 2005
' -------------------------------------------------------'
Option Explicit
Dim objWMIService, objProcess
Dim strShell, objProgram, strComputer, strExe, strInput
strExe = "rundll32.exe user32.dll,LockWorkStation"
' Input Box to get name of machine to run the process
Do
strComputer = (InputBox(" ComputerName to Run Script",_
"Computer Name"))
If strComputer <> "" Then
strInput = True
End if
Loop until strInput = True
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")
' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe
'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
'WScript.echo "Created: " & strExe & " on " & strComputer
WSCript.Quit
' End of Example of a Process VBScript
Running rundll32.exe user32.dll,LockWorkStation on my Win7 64 bit locks the screen, so this seems quite OK. But when looking at http://msdn.microsoft.com/en-us/library/windows/desktop/aa376875(v=vs.85).aspx I read
The LockWorkStation function is callable only by processes running on
the interactive desktop. In addition, the user must be logged on, and
the workstation cannot already be locked.
I have no experience with WMI but I assume that WMI does not run rundll32.exe on the interactive desktop!?
This is working for me with remote Windows 7 x64 systems :
psexec.exe -accepteula \\REMOTECOMPUTERNAME -i -s %windir%\system32\rundll32.exe user32.dll,LockWorkStation
Regards
I want to know, can I run a script on my computer that will return the value of a registry entry from another PC on the same network?
For instance if I wanted to know if a PC had AVG anti-virus installed, could I run a script to return the version number of AVG installed on that PC, and if it's not installed to just say it can't find it?
If it helps I know the IP, MAC address, Service TAG and computer name of the remote PC.
It would be good to reference Connecting to WMI on a Remote Computer (MSDN) and Scripts to manage Registry
Sample code would look something like this (taken from ActiveXperts):
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"
strValueName = "UIHost"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_
strValueName,strValue
StdOut.WriteLine "The Windows logon UI host is: " & strValue
Where strComputer value would be replaced with the name / address of the machine.