Jump to content

Installing software by different computer names


bjp106
 Share

Recommended Posts

Ok, I've got a script that Im looking for a little direction. This script mainly goes off of computer names (many computer labs) and installs two different versions of software (teacher.msi and student.msi). First for a little background info, in the first IF statement I have a computer name with 1C05-00, -00 indicates to me that it's the 'teacher' computer. Anything thats 1C05-xx, xx being could be any random number, whether its 1C05-1 or 1C05-28, these are 'student' computers.

My Questions:

1. In my ElseIf statements, I am aware that what I have listed below will not work, but what I am trying to accomplish is how the elseif can match any random number from 1C05-xx, indicating a student computer?

AND/OR

2. Is there any easier way to accomplish this than having many IF statements, as I will have many many other labs (if Then's) in this script?

Below is part of my script (it goes on and on) and will continue on for many labs, but for the sake of this post, I've only included 3 labs.

If StringLeft(@ComputerName, 4) == "1C05-00" Then
   ToolTip("Installing: Faronics Insight Teacher...", 0,0)
   RunWait("msiexec /I H:\Insight\Teacher.msi /qn ADVANCED_OPTIONS=1 CHANNEL=1 TASK_MANAGER_LIMIT=0")
   ;Does installing the teacher cause the machine to reboot?
ElseIf StringLeft(@ComputerName, 4) == "1C05-xx"
   RunWait("msiexec /I H:\Insight\Student.msi /qn ADVANCED_OPTIONS=1 CHANNEL=1")
EndIf

;Reading/Public lab
If StringLeft(@ComputerName, 4) == "1E04-00" Then
   ToolTip("Installing: Faronics Insight Teacher...", 0,0)
   RunWait("msiexec /I H:\Insight\Teacher.msi /qn ADVANCED_OPTIONS=1 CHANNEL=5 TASK_MANAGER_LIMIT=0")
   ;Does installing the teacher cause the machine to reboot?
ElseIf StringLeft(@ComputerName, 4) == "1E04-xx"
   RunWait("msiexec /I H:\Insight\Student.msi /qn ADVANCED_OPTIONS=1 CHANNEL=5")
EndIf

;Write Place A
If StringLeft(@ComputerName, 4) == "2C3A-00" Then
   ToolTip("Installing: Faronics Insight Teacher...", 0,0)
   RunWait("msiexec /I H:\Insight\Teacher.msi /qn ADVANCED_OPTIONS=1 CHANNEL=3 TASK_MANAGER_LIMIT=0")
   ;Does installing the teacher cause the machine to reboot?
ElseIf StringLeft(@ComputerName, 4) == "2C3A-xx"
   RunWait("msiexec /I H:\Insight\Student.msi /qn ADVANCED_OPTIONS=1 CHANNEL=3")
EndIf

I might be over-thinking this, but am looking for some direction

Link to comment
Share on other sites

Local $sHost = StringLeft(@ComputerName, 4)
Switch $sHost
  Case "1E04-00"

  Case "2C31-00"

  [etc]
EndSwitch

EDIT: Set hostname in a variable ... derp

EDIT2: This code smells funny... specifically StringLeft(@ComputerName, 4) will never equal "1E04-00" =/

EDIT3: Let's try this...

Local $sHost = StringLeft(@ComputerName, 4)
Local $sCode = StringMid(@ComputerName, 6, 2)
Local $iChannel
Switch $sHost
  Case "1E04"
    $iChannel = 1
  Case "2C31"
    $iChannel = 5
  Case "2C3A"
    $iChannel = 3
EndSwitch

Switch $sCode
  Case "00"
    ToolTip("Installing: Faronics Insight Teacher...", 0,0)
    RunWait("msiexec /I H:InsightTeacher.msi /qn ADVANCED_OPTIONS=1 CHANNEL=" & $iChannel & " TASK_MANAGER_LIMIT=0")
  Case "xx"
    RunWait("msiexec /I H:InsightStudent.msi /qn ADVANCED_OPTIONS=1 CHANNEL=" & $iChannel)
EndSwitch
Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Welcome to AutoIt and the forum!

is a small but easy to configure software installer example script. It has a single configuration file but the script could be easily changed to create a config file for each computer room (e.g. 1C05.ini) with a separate tab for students and teachers or even a serate config file for students and teachers.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Would something like this be helpful?

If StringMid(@ComputerName, 5, 3) = "-00" Then ; reads the 5th through the 8th character of the computer name, if it equals -00 it's a teacher machine, do this
   ToolTip("Installing: Faronics Insight Teacher...", 0,0)
   RunWait("msiexec /I H:InsightTeacher.msi /qn ADVANCED_OPTIONS=1 CHANNEL=1 TASK_MANAGER_LIMIT=0")
   ;Does installing the teacher cause the machine to reboot?
Else ; if it doesn't equal -00 then it's a studen machine, do this
   RunWait("msiexec /I H:InsightStudent.msi /qn ADVANCED_OPTIONS=1 CHANNEL=1")
EndIf

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

created a 3rd edit to my above post to take into account the different channels and teacher/student.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

I'd prefer a more flexible solution.

That means: If a new program needs to be installed you shouldn't need to change your script. The script should contain logic, error handling, logging etc. The data to be processed should be kept in an INI file, text file, database or ...

This should be quite easy with the software installer I proposed above.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Agreed. The install program linked by water is pretty nice.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

These have all been REALLY helpful!

@water - that looks great, and I can definitely build on that for future projects, however for this specific example (which I did say before) I want it to be automated, no user intervention. But thanks!

@Mechaflash - Your "Edit 3" looks more like what I'm looking for! I didnt know anything about switches and cases. I think this will shrink my script up quite a bit.

-Question - for Case "xx" how can autoit interpret whatever that random number is whether if its 1E04-2 or -35?

-And if the computer name would be lets say 1E04-15, we assume the machine will not get case "00" b/c its not a teacher machine, but how will the script know to assign the correct channel for Case "xx"? Hopefully that question is clear

Thanks

Link to comment
Share on other sites

You can't use the Case statement that has the XX in it, you'd need to use a Case Else in its place. That way if the computer name isn't ####-00 it will install the student software, and only install the instructor software if the computer name is ####-00.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

As Brew stated, just change it to this:

Local $sHost = StringLeft(@ComputerName, 4)
Local $sCode = StringMid(@ComputerName, 6, 2)
Local $iChannel
Switch $sHost
  Case "1E04"
    $iChannel = 1
  Case "2C31"
    $iChannel = 5
  Case "2C3A"
    $iChannel = 3
EndSwitch

Switch $sCode
  Case "00"
    ToolTip("Installing: Faronics Insight Teacher...", 0,0)
    RunWait("msiexec /I H:InsightTeacher.msi /qn ADVANCED_OPTIONS=1 CHANNEL=" & $iChannel & " TASK_MANAGER_LIMIT=0")
; Case "xx" ; <<<<<<<<<<<<<<<<<<<<<< CHANGED FROM
  Case Else ; <<<<<<<<<<<<<<<<<<<<<< CHANGED TO
    RunWait("msiexec /I H:InsightStudent.msi /qn ADVANCED_OPTIONS=1 CHANNEL=" & $iChannel)
EndSwitch

However still look into the link that Water provided as it can give you a long term solution to installation applications that's reusable.

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Yes I will look into Water's script as I can actually use this in the future for some stuff. I changed up my script a little here and there based on the example you gave and it was dead on, works. I've added another case in there for other items, everything works great. Thanks for your direction

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
 Share

  • Recently Browsing   0 members

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