Issue while executing a vb script upon machine startup - vbscript

I have a vbscript that adds a user to the local group "Administrators" which should run upon machine startup.
the basic code applied in the script is as follows:
Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")
' Get user object
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUser & ",user")
' Add user to group
objGroup.Add(objUser.ADsPath)
Now I added a registry string to the following path:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
Name : addUser
Value : "E:\addUser.vbs"
Now the peculiar behavior which I have noticed is that when a non-admin user logs in the script doesn't run. It only runs for members of Administrators group.
If this behavior is expected, then is there a way to by pass this (maybe run it under the Administrator or SYSTEM account).
Thanks and Regards,
Wriju

Related

Stopping Multiple Services Windows 7 using VBScript

During my internet searches, I have found a script that is supposed to stop a service. The current script runs, finds the services specified in an array, but doesn't seem to stop them. When the script outputs the services' State, it's still running. Below is the script.
sComputer = "."
aTargetSvcs= Array("mysql","Apache2.4")
Set oWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\" _
& sComputer & "\root\cimv2")
Set cServices = oWMIService.ExecQuery("SELECT * FROM Win32_Service")
For Each oService In cServices
For Each sTargetSvc In aTargetSvcs
If LCase(oService.Name) = LCase(sTargetSvc) Then
If oService.State <> "Stopped" Then
oService.StopService()
Wscript.Echo oService.State
End If
End If
Next
Next
I am just testing it out with mysql and Apache2.4 services, but when this works, it will be deployed with a group policy to temporarily stop some AV services that are interfering with a domain modifier script.
The issue is likely a lack of permission in the context of the running script.
If you run the script from the command line make sure to start it through an Elevated Command Prompt, in modern Windows Operating Systems an elevated Command Prompt is denoted by the prefix Administrator: in the Window Title.
If you run the script from a Shortcut link make sure to specify Run As Administrator in the Advanced Properties screen.

Log on as local administrator in VBS

I have what should be a very simple script. I have a series of 6 PCs that I need to check the existence of a file and report back. Where the difficulty lies is that these devices are not part of AD and are part of a work group. From windows explorer using C$ I'm prompted to log on as a local administrator on the remote PC. How can I perform the same logon and automate the process using the script below?
Set objFSO = CreateObject("Scripting.FileSystemObject")
For i = 1 To 6
If objFSO.FileExists("\\10.4.55." & i & "\c$\Program Files\X-1 Technologies\offline.fla") Then
Wscript.Echo "Reg:" & i & " Off-Line."
Else
Wscript.Echo "Reg:" & i & " On-Line."
End If
Next
Thanks, Lloyd

how to run a vb script without user intreaction in a LAN?

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.

How to retrieve registry values remotley using vbs or batch files

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.

Detect Windows CE in vBScript ( Logon script )

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.

Resources