Category Archives: VBS Files

Any code related to vb script files and logonscripts

Enable/Disable UAC | VBS

This will display a popup showing whether UAC is “Evalated” or “Not Evalated” using VBS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Dim oShell, oExec, szStdOut
 
szStdOut = ""
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec("whoami /groups")
 
Do While (oExec.Status = cnWshRunning)
WScript.Sleep 100
if not oExec.StdOut.AtEndOfStream then
szStdOut = szStdOut & oExec.StdOut.ReadAll
end if
Loop
select case oExec.ExitCode
case 0
if not oExec.StdOut.AtEndOfStream then
szStdOut = szStdOut & oExec.StdOut.ReadAll
end if
if instr(szStdOut,"S-1-16-12288") Then
wscript.echo "Elevated"
else
if instr(szStdOut,"S-1-16-8192"Then
wscript.echo "Not Elevated"
else
wscript.echo "Unknown!"
end if
end if
case else
if not oExec.StdErr.AtEndOfStream then
wscript.echo oExec.StdErr.ReadAll
end if
end select

Thanks to: http://blogs.technet.com/b/jhoward/archive/2008/11/19/how-to-detect-uac-elevation-from-vbscript.aspx

Show Host Name via VBS (ShowHost.vbs)

Simple script to show host name of the local machine in a popup window add code to “ShowHost.vbs”

Dim Shell
Dim CompName
Set Shell = WScript.CreateObject("WScript.Shell")
CompName = Shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Msgbox "Your Computer name is " & CompName

Popup Test

I was using this to test GPOs were run at user login. if the popup displayed then i knew the object had been executed.

bat: START CMD /C "ECHO Popup Test && PAUSE"

exe: popup-test.exe

vbs (will call and execute the exe from the specified location):

Set wshShell = WScript.CreateObject ("WSCript.shell")
wshshell.run "%userprofile%\desktop\popup-test.exe", 6, True
set wshshell = nothing

Add Network Printer via VBS

Use the script below to add a network printer, you can simply dump this into a txt file, rename to a .VBS and change the printer addresses (these need to be shared of course!)
The last bit of code should stop the “Error: 8007007B – the filename, directory name, or volume label syntax is incorrect” as it will keep retrying the connection to the printer share if the network is slow and timming out etc.

Last bit is to drop the script into the DC netlogon and add to group policy! BAMM!


Dim net
Set net = CreateObject("WScript.Network")
net.AddWindowsPrinterConnection "\\server\printer"
net.SetDefaultPrinter "\\server\printer"

MapPrinter "\\server\printer"

Sub MapPrinter(strPrinter)
On Error Resume Next
Set objNetwork = CreateObject("WScript.Network")
boolConnected = False
intAttempts = 1
While boolConnected = False And intAttempts <= 5
Err.Clear
objNetwork.AddWindowsPrinterConnection strPrinter
If Err.Number <> 0 Then
intAttempts = intAttempts + 1
WScript.Sleep 2000
Else
boolConnected = True
End If
Wend
End Sub

“Active Desktop Recovery” / Script Error

“Active Desktop Recovery”

“An error has occurred in a script on this page”

Not 100% sure why this error occurs, however if you bung this information into a VBS file and run “hey-presto” the error is gone and the background is back to normal. I have only seen this when there is a GP in place that sets the background and doesn’t allow it to be changed by the user, I think this could be why it can’t just be changed back!

Most other fixes I’ve tried mean you have to reset the computer or uninstall/reinstall Internet Explorer (IE), I must have wasted hours on this problem until I found this script!

Option Explicit
' Create the Shell object
Dim objShell
Set objShell = CreateObject("WScript.Shell")
'Change values that mess up IE 7 from decimal 272 to 0
objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Internet
Explorer\Desktop\SafeMode\Components\DeskHtmlVersion", "0",
"REG_DWORD"
objShell.AppActivate "Program Manager"
objShell.SendKeys "{F5}"
WScript.Quit

Report of all Users and Groups in my AD (DomainUinfo.vbs)

I usually get asked a lot for lists, specifically lists of AD users and members of groups etc. There are a couple of methods to obtain this…

Output user list in txt format using CMD:

  • net user /domain > C:users.txt (Only Lists Logon Usernames / no OU or Group Info)

Output user list in .txt format (more detail) using VBS:

  • Simple VBS Script to printout the AD information
  • Text file output to the same folder the script was run from…
  • I’ve slightly tweaked this script to make the output data more easy on the eyes.

Continue reading

BGinfo Auto Background set @ Login (*.VBS)

“bginfo_admin_background.vbs”

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "\\domain.com\NETLOGON\Logon_Software\bginfo.exe \\domain.com\NETLOGON\Logon_Software\BGINFO_background.bgi /timer:0", 1, True

I usually do this layout:

“<Host Name>”

Default Gateway: <Default Gateway>
IP Address: <IP Address>
Logon Domain: <Logon Domain>
Logon Server: <Logon Server>
Machine Domain: <Machine Domain>
OS Version: <OS Version>
Service Pack: <Service Pack>

Easy zip up of these settings here

Requires BGinfo: Sysinternals