Sign in to follow this  
Followers 0
Ben Sherrill

Runasset W/ Filemove- Filecopy

5 posts in this topic

#1 ·  Posted (edited)

Ok so here is the deal, I am in charge of setting up a script that will push a new INI file out to all users machines. This script works great if the users is an Admin on their machine. However not all are admins. If the users are not admins on the machine the the new INI files are not pushed out. The script goes out and uses the FILEMOVE to rename the old INI files to _oldcat.ini and then I use FileCopy to copy the new files to the same directory. The boss man wants them in the same directory, but at this point if someone can help me figure souething out I dont mind moving the old files to a new place. Apparently using the RUNASSET does nothing for Moving Copying or renaming files. Anyone have any Ideas? The code is below

;Use this for now to write a file to a server so we know which machines are not getting the update
$admin = IsAdmin()
If $admin Then
Else
  MsgBox(4096, "SAPLogon Update Issue", "Message to user to contact Helpdesk for update.")
   $file = FileOpen("\\Server\pc_info\SAPComputers.csv", 1)
   FileWrite($file, @CRLF & @ComputerName)
   FileClose($file)
   Exit
EndIf

;Use Select Statement to check if the machine has been updated already.
Select
    
Case @OSVersion = "WIN_XP"
; Check to see if This script has run on the computer before. If so then exit
If FileExists("C:\WINDOWS\SAPMSG_oldcat.INI") Then
 ;Messege box used to check script and make sure if file found that the script is exiting.
 ;MsgBox(4096,"SAPLogon Update","Your machine has already been updated")
   Exit
Else
EndIf

Case @OSVersion = "WIN_2000"
    If FileExists("C:\WINNT\SAPMSG_oldcat.INI") Then
 ;Messege box used to check script and make sure if file found that the script is exiting.
 ;MsgBox(4096,"SAPLogon Update","Your machine has already been updated")
   Exit
Else
EndIf

Case Else
    
    If FileExists("C:\Windows\SAPMSG_oldcat.INI") Then
 ;Messege box used to check script and make sure if file found that the script is exiting.
 ;MsgBox(4096,"SAPLogon Update","Your machine has already been updated")
   Exit
Else
EndIf
EndSelect

;Use Select Statement to update machine according to Windows Version.
Select
   
   Case @ComputerName = "PASCATWELLSRL"
      MsgBox(4096, "Robert Wells", "You are logging on to " & @ComputerName & ". This machine will not get the SAP Updates because of special configurations.")
      Exit
      
   Case @ComputerName = "CLRCATRIJNIEJ1"
      MsgBox(4096, "John Rijnierse", "You are logging on to " & @ComputerName & ". This machine will not get the SAP Updates because of special configurations.")
      Exit
      
   Case @OSVersion = "WIN_XP";Check if machine is Windows XP
    ; Make sure SAP4.6D is installed on the users Machine
      $FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")
      If $FindID = -1 Then
         MsgBox(0, "Error", "Could Not find SAP GUI!  Please contact CIS")
         Exit
      EndIf
    ;Rename Old SAP INI Files
      FileMove("C:\WINDOWS\SAPMSG.INI", "C:\WINDOWS\SAPMSG_oldcat.INI")
      FileMove("C:\WINDOWS\SAPLogon.INI", "C:\WINDOWS\SAPlogon_oldcat.INI")
    ;Copy New SAP INI files to users computer
      FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI", "C:\Windows\SAPLOGON_LB.INI")
      FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI", "C:\windows\SAPmsg.INI")
    ;Rename SapLogon_lb.ini to SapLogon.ini
      FileMove("C:\WINDOWS\SAPLogon_lb.INI", "C:\WINDOWS\SAPlogon.INI")
        Exit
      
   Case @OSVersion = "WIN_2000";Check if machine is Windows 2000
    ; Make sure SAP4.6D is installed on the users Machine
      $FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")
      If $FindID = -1 Then
         MsgBox(0, "Error", "Could Not find SAP GUI!  Please contact CIS")
         Exit
      EndIf
    ;Rename Old SAP INI Files
      FileMove("C:\WINNT\SAPMSG.INI", "C:\WINNT\SAPMSG_oldcat.INI")
      FileMove("C:\WINNT\SAPLogon.INI", "C:\WINNT\SAPlogon_oldcat.INI")
    ;Copy New SAP INI files to users computer
      FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI", "C:\WINNT\SAPLOGON_LB.INI")
      FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI", "C:\WINNT\SAPmsg.INI")
    ;Rename SapLogon_lb.ini to SapLogon.ini
      FileMove("C:\WINNT\SAPLogon_lb.INI", "C:\WINNT\SAPlogon.INI")

       Exit
      
   Case Else
    ;Make sure SAP4.6D is installed on the users Machine
      $FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")
      If $FindID = -1 Then
         MsgBox(0, "Error", "Could Not find SAP GUI!  Please contact CIS")
         Exit
      EndIf
    ;Rename Old SAP INI Files
      FileMove("C:\WINDOWS\SAPMSG.INI", "C:\WINDOWS\SAPMSG_oldcat.INI")
      FileMove("C:\WINDOWS\SAPLogon.INI", "C:\WINDOWS\SAPlogon_oldcat.INI")
    ;Copy New SAP INI files to users computer
      FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI", "C:\Windows\SAPLOGON_LB.INI")
      FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI", "C:\windows\SAPmsg.INI")
    ;Rename SapLogon_lb.ini to SapLogon.ini
      FileMove("C:\WINDOWS\SAPLogon_lb.INI", "C:\WINDOWS\SAPlogon.INI")
         Exit
EndSelect
Exit
Edited by Ben Sherrill

Share this post


Link to post
Share on other sites



You might look at JdeB's http://www.autoitscript.com/fileman/users/jdeb/scriptlets/admin.au3

Probably better in your case would be to use a batch file that does all the file moves. AutoIt CAN RunAsSet a batch file. (You could either FileInstall a batch file or create it with FileWriteLine.)

Hope that helps


Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If you check the help file and look for RunAsSet function, you will notice that only work with Run() and Ruwait() functions. Any other functions, like FileMove() or FileCopy() will be ignore by RunAsSet.

Now to work around this I will do something like:

If Not IsAdmin() Then
   $file = FileOpen("\\Server\pc_info\SAPComputers.csv", 1)
   FileWrite($file, @CRLF & @ComputerName)
   FileClose($file)
   RunAsSet ( ["user", "domain", "password" [, options]] )
EndIf

and then I will change all FileCopy and FileMove for RunWait(@Comspec & ' /c Copy') or RunWait(@Comspec & ' /c Rename'):

Case @OSVersion = "WIN_XP";Check if machine is Windows XP
; Make sure SAP4.6D is installed on the users Machine
    $FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")
    If $FindID = -1 Then
        MsgBox(0, "Error", "Could Not find SAP GUI!  Please contact CIS")
        Exit
    EndIf
;Rename Old SAP INI Files
    RunWait(@ComSpec & ' /c Rename "C:\WINDOWS\SAPMSG.INI" "C:\WINDOWS\SAPMSG_oldcat.INI"', @WorkingDir, @SW_HIDE)
    RunWait(@ComSpec & ' /c Rename "C:\WINDOWS\SAPLogon.INI" "C:\WINDOWS\SAPlogon_oldcat.INI"', @WorkingDir, @SW_HIDE)
;Copy New SAP INI files to users computer
    RunWait(@ComSpec & ' /c Copy "\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI" "C:\Windows\SAPLOGON_LB.INI"', @WorkingDir, @SW_HIDE)
    RunWait(@ComSpec & ' /c Copy "\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI" "C:\windows\SAPmsg.INI"', @WorkingDir, @SW_HIDE)
;Rename SapLogon_lb.ini to SapLogon.ini
    RunWait(@ComSpec & ' /c Rename "C:\WINDOWS\SAPLogon_lb.INI" "C:\WINDOWS\SAPlogon.INI"', @WorkingDir, @SW_HIDE)  
    Exit

I hope this will help you.

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

If you check the help file and look for RunAsSet function, you will notice that only work with Run() and Ruwait() functions. Any other functions, like FileMove() or FileCopy() will be ignore by RunAsSet.

Now to work around this I will do something like:

If Not IsAdmin() Then
   $file = FileOpen("\\Server\pc_info\SAPComputers.csv", 1)
   FileWrite($file, @CRLF & @ComputerName)
   FileClose($file)
   RunAsSet ( ["user", "domain", "password" [, options]] )
EndIf

and then I will change all FileCopy and FileMove for RunWait(@Comspec & ' /c Copy') or RunWait(@Comspec & ' /c Rename'):

Case @OSVersion = "WIN_XP";Check if machine is Windows XP
; Make sure SAP4.6D is installed on the users Machine
    $FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")
    If $FindID = -1 Then
        MsgBox(0, "Error", "Could Not find SAP GUI!  Please contact CIS")
        Exit
    EndIf
;Rename Old SAP INI Files
    RunWait(@ComSpec & ' /c Rename "C:\WINDOWS\SAPMSG.INI" "C:\WINDOWS\SAPMSG_oldcat.INI"', @WorkingDir, @SW_HIDE)
    RunWait(@ComSpec & ' /c Rename "C:\WINDOWS\SAPLogon.INI" "C:\WINDOWS\SAPlogon_oldcat.INI"', @WorkingDir, @SW_HIDE)
;Copy New SAP INI files to users computer
    RunWait(@ComSpec & ' /c Copy "\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI" "C:\Windows\SAPLOGON_LB.INI"', @WorkingDir, @SW_HIDE)
    RunWait(@ComSpec & ' /c Copy "\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI" "C:\windows\SAPmsg.INI"', @WorkingDir, @SW_HIDE)
;Rename SapLogon_lb.ini to SapLogon.ini
    RunWait(@ComSpec & ' /c Rename "C:\WINDOWS\SAPLogon_lb.INI" "C:\WINDOWS\SAPlogon.INI"', @WorkingDir, @SW_HIDE)  
    Exit

I hope this will help you.

Interesting.. Thanks to both of you I'll try these out and see what comes of it. I'll let you know what happens

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Cyber Slug that script you sent me works i had to tweek mine though with it. Thank you both for helping me out.

Here is the code Sorry I had to use the quote bracket to show the changes easier

AutoItSetOption("RunErrorsFatal", 0)

AutoItSetOption("TrayIconHide", 1)

Break(0)

$USERNAME = "username"

$PASSWORD = "password"

$RUN = 0 ; run indicator

;Use Select Statement to check if the machine has been updated already.

Select

Case @OSVersion = "WIN_XP"

; Check to see if This script has run on the computer before. If so then exit

If FileExists("C:\WINDOWS\SAPMSG_oldcat.INI") Then

;Messege box used to check script and make sure if file found that the script is exiting.

;MsgBox(4096,"SAPLogon Update","Your machine has already been updated")

Exit

Else

EndIf

Case @OSVersion = "WIN_2000"

If FileExists("C:\WINNT\SAPMSG_oldcat.INI") Then

;Messege box used to check script and make sure if file found that the script is exiting.

;MsgBox(4096,"SAPLogon Update","Your machine has already been updated")

Exit

Else

EndIf

Case Else

If FileExists("C:\Windows\SAPMSG_oldcat.INI") Then

;Messege box used to check script and make sure if file found that the script is exiting.

;MsgBox(4096,"SAPLogon Update","Your machine has already been updated")

Exit

Else

EndIf

EndSelect

;Use Select Statement to update machine according to Windows Version.

Select

Case @ComputerName = "PASCATWELLSRL"

MsgBox(4096, "Robert Wells", "You are logging on to " & @ComputerName & ". This machine will not get the SAP Updates because of special configurations.")

Exit

Case @ComputerName = "CLRCATRIJNIEJ1"

MsgBox(4096, "John Rijnierse", "You are logging on to " & @ComputerName & ". This machine will not get the SAP Updates because of special configurations.")

Exit

Case @OSVersion = "WIN_XP";Check if machine is Windows XP

; Make sure SAP4.6D is installed on the users Machine

$FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")

If $FindID = -1 Then

MsgBox(0, "Error", "Could Not find SAP GUI! Please contact CIS")

Exit

EndIf

;Rename Old SAP INI Files

FileMove("C:\WINDOWS\SAPMSG.INI", "C:\WINDOWS\SAPMSG_oldcat.INI")

FileMove("C:\WINDOWS\SAPLogon.INI", "C:\WINDOWS\SAPlogon_oldcat.INI")

;Copy New SAP INI files to users computer

FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI", "C:\Windows\SAPLOGON_LB.INI")

FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI", "C:\windows\SAPmsg.INI")

;Rename SapLogon_lb.ini to SapLogon.ini

FileMove("C:\WINDOWS\SAPLogon_lb.INI", "C:\WINDOWS\SAPlogon.INI")

Exit

Case @OSVersion = "WIN_2000";Check if machine is Windows 2000

;This is where I added the other script in. For some reason when run under XP it bombs out

If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]

If $RUN = 0 Then

RunAsSet($USERNAME, "domain", $PASSWORD)

Run('"' & @ScriptFullPath & '" " 1"')

If @error Then MsgBox(4096 + 32, "Error", "Error starting under admin mode. If you're a Clear Lake user, call Ben at 557, or if you're at Bayport, call the CIS HelpDesk at 618 to get your SAP settings updated. ")

Exit

EndIf

; Make sure SAP4.6D is installed on the users Machine

$FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")

If $FindID = -1 Then

MsgBox(0, "Error", "Could Not find SAP GUI! Please contact CIS")

Exit

EndIf

;Rename Old SAP INI Files

FileMove("C:\WINNT\SAPMSG.INI", "C:\WINNT\SAPMSG_oldcat.INI")

FileMove("C:\WINNT\SAPLogon.INI", "C:\WINNT\SAPlogon_oldcat.INI")

;Copy New SAP INI files to users computer

FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI", "C:\WINNT\SAPLOGON_LB.INI")

FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI", "C:\WINNT\SAPmsg.INI")

;Rename SapLogon_lb.ini to SapLogon.ini

FileMove("C:\WINNT\SAPLogon_lb.INI", "C:\WINNT\SAPlogon.INI")

Exit

Case Else

;Make sure SAP4.6D is installed on the users Machine

$FindID = FileFindFirstFile("C:\Program Files\SAPpc\SAPGUI\SAPLOGON.EXE")

If $FindID = -1 Then

MsgBox(0, "Error", "Could Not find SAP GUI! Please contact CIS")

Exit

EndIf

;Rename Old SAP INI Files

FileMove("C:\WINDOWS\SAPMSG.INI", "C:\WINDOWS\SAPMSG_oldcat.INI")

FileMove("C:\WINDOWS\SAPLogon.INI", "C:\WINDOWS\SAPlogon_oldcat.INI")

;Copy New SAP INI files to users computer

FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPLOGON_LB.INI", "C:\Windows\SAPLOGON_LB.INI")

FileCopy("\\server\apps\SAP\ALB_LOAD_BALANCING\SAPmsg.INI", "C:\windows\SAPmsg.INI")

;Rename SapLogon_lb.ini to SapLogon.ini

FileMove("C:\WINDOWS\SAPLogon_lb.INI", "C:\WINDOWS\SAPlogon.INI")

Exit

EndSelect

Exit

Edited by Ben Sherrill

Share this post


Link to post
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
Sign in to follow this  
Followers 0