vinodreddy597 Posted May 31, 2013 Share Posted May 31, 2013 Hi,Here is my vbscript which checks the computer name and then it'll run the registry key if the first 3 letters of machine code matches. But unfortunately it's not working. Please help me..'------------------------------' Computer name'------------------------------Dim COMPUTER_NAMEDim oFso, sShell, oShellEnv, target, sourceSet oFso = CreateObject("Scripting.FileSystemObject")Set oShell = WScript.CreateObject("WScript.Shell")Set oShellEnv = oShell.Environment("Process")COMPUTER_NAME = oShellEnv("ComputerName")'MsgBox COMPUTER_NAME'------------------------------' First Three'------------------------------Dim FIRST_THREEFIRST_THREE = Mid(COMPUTER_NAME, 1, 3)'MsgBox FIRST_THREE'------------------------------' Get Run Registry'------------------------------Dim IS_RUN_REGISTRYIf FIRST_THREE = "HAC" ThenIS_RUN_REGISTRY = trueElseIS_RUN_REGISTRY = falseEnd If'MsgBox "[" & FIRST_THREE & "][" & IS_RUN_REGISTRY & "] "'------------------------------' Run Registry if needed'------------------------------Set regFile = "Genesis.reg"If IS_RUN_REGISTRY ThenSet oShell = CreateObject("Wscript.Shell")sRegFile = regFileoShell.Run "regedit.exe /s " & Chr(34) & sRegFile & Chr(34), 0, TrueEnd IfEdit by Gsm added code box Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 31, 2013 Share Posted May 31, 2013 Your problem is this, the error means this is missing'------------------------------' Run Registry if needed'------------------------------Set regFile = "Genesis.reg"Here I redid the script so it a little more cleaner and added a FileExists check'-> This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use.'-> This is only posted as example code and meant only to used as such.'-> Objects For RuntimeDim Act :Set Act = CreateObject("WScript.Shell")Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'-> ComputerNameDim CName :CName = Act.ExpandEnvironmentStrings("%ComputerName%")'MsgBox CName,4128,"Test Computer Name"Dim IS_RUN_REGISTRY'-> Check For RegistryHACIf UCase(Left(CName,3)) = "HAC" ThenIS_RUN_REGISTRY = TrueElseIS_RUN_REGISTRY = FalseEnd If'-> If IS_RUN_REGISTRY = True And The Reg File ExistsIf Fso.FileExists("Genesis.reg") And IS_RUN_REGISTRY Then' Act.Run("regedit.exe /s " & Chr(34) & "Genesis.reg" & Chr(34)), 0, TrueMsgBox "Confirm Reg File"ElseIf Fso.FileExists("Genesis.reg") And IS_RUN_REGISTRY = False ThenMsgBox "ComputerName match was False",4128,"No Match ComputerName"ElseMsgBox "Missing Genesis.reg please make sure it in the" & vbCrLf &_"Genesis.reg is in the same folder as this script",4128,"Missing Reg File"End If Link to comment Share on other sites More sharing options...
Yzöwl Posted May 31, 2013 Share Posted May 31, 2013 It's not often that I see a VBS question and deliberately ignore a VBS solution, but at this time I see no good reason to ignore a Windows Command Script.SCRIPT.CMD@IF %COMPUTERNAME:~,3%' EQU HAC' REGEDIT /S GENESIS.REGThe two single quotes/apostrophes aren't necessary, they are included because they are harmless but improve the look of the code under the forum formatting scheme Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now