Jump to content

Would like to only run this script if computer name is a certain name.


Recommended Posts

Hi

My 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 by Yzöwl
code tags added
Link to comment
Share on other sites


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 :TEST

To:

call :%COMPUTERNAME%

goto :eof

Option 2:

Using the logic flow as you wrote it.

Change:

if "%COMPUTERNAME%" == "Test" goto :TEST

To:

if /i "%COMPUTERNAME%" == "Test" goto :TEST

goto :eof

Option 3:

Exit the script when the condition does not match.

Change:

if "%COMPUTERNAME%" == "Test" goto :TEST

To:

if /i "%COMPUTERNAME%" NEQ "Test" goto :eof

HTH

Link to comment
Share on other sites

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 is

Basically here is the if's

if /i "%COMPUTERNAME%" == "2F26" goto :2F26

if /i "%COMPUTERNAME%" == "2F24" goto :2F24

if /i "%COMPUTERNAME%" == "2F20" goto :2F20

if /i "%COMPUTERNAME%" == "2F18" goto :2F18

2F24 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 by clivebuckwheat
Link to comment
Share on other sites

Here is another way of doing what you want using vbs scripting

I 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 1

Template 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 2

Save As RunOnce_Demo.vbs


'-> Objects For Run Time
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Varibles For Runtime
Dim C1, Chk, Col, Cmp, ComputerNames, Obj, Rpt, Str
Cmp =Act.ExpandEnvironmentStrings("%ComputerName%")
'-> Array For Computer Names
ComputerNames = 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 active

RunOnce_Demo.vbs.txt

Link to comment
Share on other sites

  • 4 years later...

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
 
:home
copy c:\test.txt "%programfiles(x86)%\Adobe\Reader 11.0\Reader\" /f
start "" "%programfiles(x86)%\Adobe\Reader 11.0\Reader\AcroRd32.EXE" /f
exit
 
:END
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...