clivebuckwheat Posted July 30, 2011 Posted July 30, 2011 (edited) HiMy script works great, now I would like to add only run this script if the computer name is equal to test, my if statement doesn't seem to work, it runs even if the computer name is NOT test. @ ECHO OFFREG ADD HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RunOnceExSET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceExNET USE Z: \\192.168.1.216\Installations Mypassword /USER:Robwrundll32.exe iernonce.dll,RunOnceExProcessif "%COMPUTERNAME%" == "Test" goto :TEST:TESTREG ADD %KEY% /V TITLE /D "Test Post Image Configurations" /fREG ADD %KEY%\010 /VE /D "Installing FireFox 3.64" /fREG ADD %KEY%\010 /V 1 /D "z:\Firefox\Firefox364.exe -ms" /fREG ADD %KEY%\015 /VE /D "Installing Java 6 Update 20" /fREG ADD %KEY%\015 /V 1 /D "z:\Java6U20\jre-6u20-windows-i586-s.exe /s /v /qn ADDLOCAL=ALL IEXPLORER=1 MOZILLA=1 SYSTRAY=0 JAVAUPDATE=0 REBOOT=Suppress" /fREG ADD %KEY%\020 /VE /D "Installing Flash Player" /fREG ADD %KEY%\020 /V 1 /D "z:\FlashPlayer\install_flash_player_10_active_x.msi /qn" /fREG ADD %KEY%\020 /V 2 /D "z:\FlashPlayer\install_flash_player_10_plugin.msi /qn" /fREG ADD %KEY%\025 /VE /D "Installing Shockwave Player" /fREG ADD %KEY%\025 /V 1 /D "z:\ShockwavePlayer\sw_lic_full_installer.msi /qn" /fREG ADD %KEY%\030 /VE /D "Installing CCleaner 2.33" /fREG ADD %KEY%\030 /V 1 /D "z:\CCleaner\ccleaner_slim_233.exe /silent" /fREG ADD %KEY%\035 /VE /D "Installing FileZilla 3.3.3" /fREG ADD %KEY%\035 /V 1 /D "z:\FileZilla\FileZilla_3.3.3_win32-setup.exe /S" /fREG ADD %KEY%\040 /VE /D "Install GomPlayer" /fREG ADD %KEY%\040 /V 1 /D "z:\GomPlayer\GOMPLAYERENSETUP.EXE /S" /fREG ADD %KEY%\045 /VE /D "Installing ImgBurn" /fREG ADD %KEY%\045 /V 1 /D "z:\ImgBurn\imageburnsetup.exe /S" /f\REG ADD %KEY%\045 /V 2 /D "REGEDIT /S z:\Imgburn\imgburnsettings.reg" /fREG ADD %KEY%\050 /VE /D "Installing Itunes-Quicktime" /fREG ADD %KEY%\050 /V 1 /D "z:\Itunes64Setup\AppleApplicationSupport.msi /qn" /fREG ADD %KEY%\050 /V 2 /D "z:\Itunes64Setup\AppleMobileDeviceSupport64.msi /qn" /fREG ADD %KEY%\050 /V 3 /D "z:\Itunes64Setup\AppleSoftwareUpdate.msi /qn" /fREG ADD %KEY%\050 /V 4 /D "z:\Itunes64Setup\Quicktime.msi /qn" /fREG ADD %KEY%\050 /V 5 /D "z:\Itunes64Setup\Bonjour64.msi /qn" /fREG ADD %KEY%\050 /V 6 /D "z:\Itunes64Setup\iTunes64.msi /qn" /fREG ADD %KEY%\055 /VE /D "Installing Adobe Reader 9.3.1" /fREG ADD %KEY%\055 /V 1 /D "z:\Reader931\AdbeRdr930_en_us.msi /qn" /fREG ADD %KEY%\055 /VE /D "Installing VLC 1.1.0" /frem REG ADD %KEY%\055 /V 1 /D "z:\VLC\vlc-1.1.0-win32.exe /S" /fREG ADD %KEY%\060 /VE /D "Installing Open Office 3.3" /fREG ADD %KEY%\060 /V 1 /D "z:\OpenOffice33\openofficeorg33.msi /qb /t openofficeorg33.mst" /fREG ADD %KEY%\090 /VE /D "Installing Microsoft Office 2010" /fREG ADD %KEY%\090 /V 1 /D "z:\Office14\setup.exe /adminfile Office2010Full.MSP" /fREG ADD %KEY%\090 /V 2 /D "REGEDIT /S z:\Office14\Excel-Add-ins.reg" /fexit:ENDecho Nothing to DO!@echo on Edited December 10, 2015 by Yzöwl code tags added
Scr1ptW1zard Posted July 30, 2011 Posted July 30, 2011 There are a couple a ways to do this:Option 1:Assuming the computer name is the label you are calling, as you wrote in your request.Change:if "%COMPUTERNAME%" == "Test" goto :TESTTo:call :%COMPUTERNAME%goto :eofOption 2:Using the logic flow as you wrote it.Change:if "%COMPUTERNAME%" == "Test" goto :TESTTo:if /i "%COMPUTERNAME%" == "Test" goto :TESTgoto :eofOption 3:Exit the script when the condition does not match.Change:if "%COMPUTERNAME%" == "Test" goto :TESTTo:if /i "%COMPUTERNAME%" NEQ "Test" goto :eofHTH
jaclaz Posted July 30, 2011 Posted July 30, 2011 One word of advice, both "/I" and "neq" need command extensions enabled:http://www.computerhope.com/if.htmthe:call :%COMPUTERNAME%goto :eofis case insensitive and needs not command extensions enabled.jaclaz
clivebuckwheat Posted July 30, 2011 Author Posted July 30, 2011 (edited) upon reflection I was wondering if it's possible to check the first 4 letters of a computer name and run my script?The script runs no matter what the computer name isBasically here is the if'sif /i "%COMPUTERNAME%" == "2F26" goto :2F26if /i "%COMPUTERNAME%" == "2F24" goto :2F24if /i "%COMPUTERNAME%" == "2F20" goto :2F20if /i "%COMPUTERNAME%" == "2F18" goto :2F182F24 is a section, 2f26 is a section etc, if the computer name is not found i'd like the script to go to:End echo Nothing to do on the screen. Edited July 31, 2011 by clivebuckwheat
allen2 Posted July 31, 2011 Posted July 31, 2011 (edited) %COMPUTERNAME:~0,4% should be the first 4 characters of %COMPUTERNAME%. Edited July 31, 2011 by allen2
gunsmokingman Posted July 31, 2011 Posted July 31, 2011 Here is another way of doing what you want using vbs scriptingI have used a only a couple of your examples in the script below.Template 1, for only a single item'-> Start Cut And Paste Template 1'-> FireFox 3.64 Var = "z:\Firefox\Firefox364.exe" If Fso.FileExists(Var) Then Act.RegWrite Key & "010\", "Installing FireFox 3.64", "REG_SZ" Act.RegWrite Key & "010\1", Var & " -ms", "REG_SZ" Else Rpt = Var End If'-> End Cut And Paste Template 1Template 2, for only a multiple items'-> Start Cut And Paste Template 2'-> Itunes-Quicktime C1 = 1 Str = Array( _ "z:\Itunes64Setup\AppleApplicationSupport.msi", _ "z:\Itunes64Setup\AppleMobileDeviceSupport64.msi", _ "z:\Itunes64Setup\AppleSoftwareUpdate.msi ", _ "z:\Itunes64Setup\Quicktime.msi", _ "z:\Itunes64Setup\Bonjour64.msi", _ "z:\Itunes64Setup\iTunes64.msi") If Fso.FileExists(Str(0)) Then Act.RegWrite Key & "050\", "Installing Itunes-Quicktime", "REG_SZ" For Each Col In Str Act.RegWrite Key & "050\" & C1, Col & " /qn", "REG_SZ" C1 = C1 + 1 Next Else For Each Col In Str Rpt = Rpt & vbCrLf & Col Next End If'-> End Cut And Paste Template 2Save As RunOnce_Demo.vbs'-> Objects For Run TimeDim Act :Set Act = CreateObject("Wscript.Shell")Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")'-> Varibles For RuntimeDim C1, Chk, Col, Cmp, ComputerNames, Obj, Rpt, StrCmp =Act.ExpandEnvironmentStrings("%ComputerName%")'-> Array For Computer NamesComputerNames = Array("2F26","2F24","2F20","2F18")'-> Loop Threw Array For Each Obj In ComputerNames '-> Code Here For Matching Computers If InStr(1,Cmp, Obj,1) Then AddUser() RunOnce()'-> Report Any Missing Apps If Len(Rpt) > 3 Then MsgBox vbTab & "Error Missing App" & vbCrLf & _ "These application path where not found, so " & vbCrLf & _ "they where not added to the RunOnceEx list." & vbCrLf & _ Rpt ,4128,"Error Missing Apps" End If WScript.Quit(0) Else Chk = False End If Next '-> Add User Function AddUser() Act.Run( _ "NET USE Z: \\192.168.1.216\Installations Mypassword /USER:Robw"),0,True End Function'-> RunOnce Function RunOnce() Dim Key, Var Key = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\" Act.Run("rundll32.exe iernonce.dll,RunOnceExProcess"),1,True Act.RegWrite Key & "TITLE", "Test Post Image Configurations", "REG_SZ"'-> Start Cut And Paste Template 1'-> FireFox 3.64 Var = "z:\Firefox\Firefox364.exe" If Fso.FileExists(Var) Then Act.RegWrite Key & "010\", "Installing FireFox 3.64", "REG_SZ" Act.RegWrite Key & "010\1", Var & " -ms", "REG_SZ" Else Rpt = Var End If'-> End Cut And Paste Template 1'-> Start Cut And Paste Template 1'-> Java 6 Update 20 Var = "z:\Java6U20\jre-6u20-windows-i586-s.exe" If Fso.FileExists(Var) Then Act.RegWrite Key & "015\", "Installing Java 6 Update 20", "REG_SZ" Act.RegWrite Key & "015\1", Var & " /s /v /qn ADDLOCAL=ALL" & _ " IEXPLORER=1 MOZILLA=1 SYSTRAY=0 JAVAUPDATE=0 REBOOT=Suppress", "REG_SZ" Else Rpt = Rpt & vbCrLf & Var End If'-> End Cut And Paste Template 1'-> Start Cut And Paste Template 2'-> Flash Player C1 = 1 Str = Array( _ "z:\FlashPlayer\install_flash_player_10_active_x.msi", _ "z:\FlashPlayer\install_flash_player_10_plugin.msi") If Fso.FileExists(Str(0)) Then Act.RegWrite Key & "020\", "Installing Flash Player", "REG_SZ" For Each Col In Str Act.RegWrite Key & "020\" & C1, Col & " /qn", "REG_SZ" C1 = C1 + 1 Next Else For Each Col In Str Rpt = Rpt & vbCrLf & Col Next End If'-> End Cut And Paste Template 2'-> Start Cut And Paste Template 1'-> Shockwave Player Var = "z:\ShockwavePlayer\sw_lic_full_installer.msi" If Fso.FileExists(Var) Then Act.RegWrite Key & "025\", "Installing Shockwave Player", "REG_SZ" Act.RegWrite Key & "025\1", Var & " /qn", "REG_SZ" Else Rpt = Rpt & vbCrLf & Var End If'-> End Cut And Paste Template 1'-> Start Cut And Paste Template 2'-> Itunes-Quicktime C1 = 1 Str = Array( _ "z:\Itunes64Setup\AppleApplicationSupport.msi", _ "z:\Itunes64Setup\AppleMobileDeviceSupport64.msi", _ "z:\Itunes64Setup\AppleSoftwareUpdate.msi ", _ "z:\Itunes64Setup\Quicktime.msi", _ "z:\Itunes64Setup\Bonjour64.msi", _ "z:\Itunes64Setup\iTunes64.msi") If Fso.FileExists(Str(0)) Then Act.RegWrite Key & "050\", "Installing Itunes-Quicktime", "REG_SZ" For Each Col In Str Act.RegWrite Key & "050\" & C1, Col & " /qn", "REG_SZ" C1 = C1 + 1 Next Else For Each Col In Str Rpt = Rpt & vbCrLf & Col Next End If'-> End Cut And Paste Template 2 End Function '-> End Of Script If No Matches Found If Chk = False Then MsgBox "This computer, " & Cmp & _ " does not match any on the list",4128,"Not A Listed Computer" End If Change from RunOnce_Demo.vbs.txt to RunOnce_Demo.vbs to make activeRunOnce_Demo.vbs.txt
rajneeshsaraswat Posted December 3, 2015 Posted December 3, 2015 i am trying this but still it works whatever the name i provide in " "i mean it still open the adobe reader. if /I "%COMPUTERNAME:~0,4%" == "hoem" goto :home :homecopy c:\test.txt "%programfiles(x86)%\Adobe\Reader 11.0\Reader\" /fstart "" "%programfiles(x86)%\Adobe\Reader 11.0\Reader\AcroRd32.EXE" /fexit :END
dencorso Posted December 3, 2015 Posted December 3, 2015 Try:if /I "%COMPUTERNAME:~0,4%" == "home" goto :home goto :end :homecopy c:\test.txt "%programfiles(x86)%\Adobe\Reader 11.0\Reader\" /fstart "" "%programfiles(x86)%\Adobe\Reader 11.0\Reader\AcroRd32.exe" /fexit :end
jumper Posted December 3, 2015 Posted December 3, 2015 (edited) if /I not "%COMPUTERNAME:~0,4%" == "hoem" goto :END Edited December 3, 2015 by jumper
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now