Showing posts with label VB Script. Show all posts
Showing posts with label VB Script. Show all posts

Monday, March 24, 2014

VB Script to work with windows environment variables

Some applications require that a folder be added to the path environment variable to find DLL's or configuration Files. this is as simple as Calling the path, then Appending a ; and thenewpath to it.

 Set ObjWsh = WScript.CreateObject("WScript.Shell")   
 Set WshEnv = objWsh.Environment("SYSTEM")   
 WshEnv("Path") = WshEnv("Path") & ";C:\PathTo\Add"  

there are 2 types of environment variables we can use - User and System. User apply only to the current user, Whereas System are system wide. the Line WshEnv=objWsh.Environment("SYSTEM") creates the WSHEnv Object set to system - so when we call the Path variable in the next line, it is the system path, and not the user path we are returning.

In this example, to append a folder to the path, we set the Path WshEnv("Path") equal to itself + the & (amperstand concatenation string) and the string we want to add (Prefixed with a semicolon, which is the Separator used in the path Variable) ";C:\PathTo\Add" (N.B to enclose this in Quotes since its a literal string)

Friday, December 6, 2013

Script to make current logged in user local admin

this script Adds the nt interactive user to the local administrators group on a pc. this has the effect of allowing the local logged on user to have local admin rights, with out granting local admin to a domain group.
 Option Explicit  
 Dim strComputer  
 Dim objNetwork, objLocalGroup  
 ' create network object for the local computer  
 Set objNetwork = CreateObject("Wscript.Network")  
 ' get the name of the local computer  
 strComputer = objNetwork.ComputerName  
 ' bind to the group  
 Set objLocalGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")  
 ' add NT Authority\Interactive to the group  
 On Error Resume Next ' suppress error in case it is already a member  
 objLocalGroup.Add("WinNT://NT Authority/Interactive")  
 On Error Goto 0  
 Set objNetwork = Nothing  
 Set objLocalGroup = Nothing  
 WScript.Quit