craigholohan Posted November 16, 2006 Share Posted November 16, 2006 Hi Guys, I am stuck again...... So thanks to JdeB and jpm I managed to sort out the file security permissions but now I am having difficulties with the RunAsSet() When I log on as just a user, double click my install file I get my inputbox, enter the admin username, click Ok and the password box pops up, I enter the pasword and my gui opens. Than I run it but nothing is extracted. If I right click my install file and select run as admin, enter the admin password, I again have to enter the admin user name and password, then it extracts and the file permissions are set and everything works. How can I extract/install without having to right click and install as admin? Below my code: expandcollapse popup #include <GUIConstants.au3> #include <File.au3> Opt ("GUIOnEventMode", 1) Global Const $Title = 'Quick NIC Changer' Global Const $Version = '3.2.0.1' Global $iMsgBoxAnswer Global $AdminName Global $AdminPass ;CHECK POWER ;=========== $AdminName = InputBox($Title, "Enter local Admin user name:", '', '', '280', '160', '-1', '-1') $AdminPass = InputBox($Title, "Enter local Admin password:", '', '*', '280', '160', '-1', '-1') RunAsSet($AdminName, @ComputerName, $AdminPass) $Form1 = GUICreate("Quick NIC Intaller", 255, 250, -1, -1) $Close = GUICtrlCreateButton("Cancel", 10, 220, 75, 25, 0) GUICtrlSetOnEvent($Close,"_Close") $Next = GUICtrlCreateButton("Next",170, 220, 75, 25, 0) GUICtrlSetOnEvent($Next,"_Next") $Group1 = GUICtrlCreateGroup("Welcome to Quick NIC installer", 10, 10, 235, 155) $Label1 = GUICtrlCreateLabel('This application is a utility for easily changing your ' & _ 'TCP/IP settings of your Local Area Network and Wireless Network connections.' & @LF & _ 'It also includes a built in tool to change you Proxy setting.'& @LF & _ @LF & _ 'Select a folder to install to or leave it to default' & @LF & _ 'Then click Next', 20, 30, 220, 120) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label1 = GUICtrlCreateLabel("Install Path :",10,182,156,20) $InstallDir = GUICtrlCreateInput("C:\Quick NIC", 80, 180, 156, 20) GUISetState(@SW_SHOW) While 1 $Inst_Message = GUICtrlRead($InstallDir) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Next() ProgressOn("Quick NIC install Progress", "Installing Please wait....", "0 percent") For $i = 0 to 100 step 1 sleep(100) ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "Complete") sleep(500) DirCreate ($Inst_Message & "\Icons") FileInstall ( "C:\IP-Changer\Final App\Icons\proxy.ico", $Inst_Message & "\Icons\proxy.ico",1) FileInstall ( "C:\IP-Changer\Final App\Icons\TarjetadeRed.ico", $Inst_Message & "\Icons\TarjetadeRed.ico",1) FileInstall ( "C:\IP-Changer\Final App\Icons\QuickNICLogo.gif", $Inst_Message & "\Icons\QuickNICLogo.gif",1) FileInstall ( "C:\IP-Changer\Final App\Icons\QuickNICLogoVert.gif", $Inst_Message & "\Icons\QuickNICLogoVert.gif",1) FileInstall ( "C:\IP-Changer\Final App\Quick NIC.exe", $Inst_Message & "\Quick NIC.exe",1) FileInstall ( "C:\IP-Changer\Final App\proxy.ini", $Inst_Message & "\proxy.ini",1) FileInstall ( "C:\IP-Changer\Final App\Ships.ini", $Inst_Message & "\Ships.ini",1) FileInstall ( "C:\IP-Changer\Final App\power.ini", $Inst_Message & "\power.ini",1) FileCreateShortcut($Inst_Message& "\Quick NIC.exe", @DesktopCommonDir & "\Quick NIC.lnk", $Inst_Message, '', 'Qiuck NIC Changer', $Inst_Message & "\Icons\TarjetadeRed.ico", '', '0') RunWait(@ComSpec & ' /c ' & 'cacls "'&$Inst_Message&'\*.*" /e /g "Everyone":F Users:F', "", @SW_HIDE) RunWait(@ComSpec & ' /c ' & 'cacls "'&@DesktopCommonDir&'\Quick NIC.lnk" /e /g "Everyone":F Users:F', "", @SW_HIDE) ProgressOff() sleep(100) If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(68,"Quick NIC install Done","Congratulations," & @CRLF & "You have successfully installed Quick NIC" & @CRLF & "Do you want to run Quick NIC now?" & @CRLF) Select Case $iMsgBoxAnswer = 6 ;Yes Run ("Quick NIC.exe",$Inst_Message) sleep(1000) Exit Case $iMsgBoxAnswer = 7 ;No Exit EndSelect EndFunc Func _Close() Exit EndFunc [END CODE] p.s not got to it yet but Case $iMsgBoxAnswer = 6 ;Yes, Run ("Quick NIC.exe",$Inst_Message) does not either work, I get a error saying something like location $Inst_Message not found. Not a biggie but if you see the proble it would be nice to know why its not working. Thanks again in advance for any help/explanation, Craig Link to comment Share on other sites More sharing options... Danny35d Posted November 16, 2006 Danny35d Active Members 809 Share Posted November 16, 2006 How can I extract/install without having to right click and install as admin?One way will be making the script to run itself as administrator. #include <GUIConstants.au3> #include <File.au3> Opt ("GUIOnEventMode", 1) Global Const $Title = 'Quick NIC Changer' Global Const $Version = '3.2.0.1' Global $iMsgBoxAnswer Global $AdminName Global $AdminPass If $CmdLine[0] <> 0 Then If $CmdLine[1] = '/runas' And $CmdLine[0] = 3 Then $AdminName = $CmdLine[2] $AdminPass = $CmdLine[3] EndIf Else ;CHECK POWER ;=========== $AdminName = InputBox($Title, "Enter local Admin user name:", '', '', '280', '160', '-1', '-1') If @error <> 0 Then Exit $AdminPass = InputBox($Title, "Enter local Admin password:", '', '*', '280', '160', '-1', '-1') If @error <> 0 Then Exit RunAsSet($AdminName, @ComputerName, $AdminPass) Run(@AutoItExe & ' /runas ' & $AdminName & ' ' & $AdminPass, '', @SW_SHOW) Exit EndIf $Form1 = GUICreate("Quick NIC Intaller", 255, 250, -1, -1) $Close = GUICtrlCreateButton("Cancel", 10, 220, 75, 25, 0) GUICtrlSetOnEvent($Close,"_Close") $Next = GUICtrlCreateButton("Next",170, 220, 75, 25, 0) GUICtrlSetOnEvent($Next,"_Next") $Group1 = GUICtrlCreateGroup("Welcome to Quick NIC installer", 10, 10, 235, 155) $Label1 = GUICtrlCreateLabel('This application is a utility for easily changing your ' & _ 'TCP/IP settings of your Local Area Network and Wireless Network connections.' & @LF & _ 'It also includes a built in tool to change you Proxy setting.'& @LF & _ @LF & _ 'Select a folder to install to or leave it to default' & @LF & _ 'Then click Next', 20, 30, 220, 120) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label1 = GUICtrlCreateLabel("Install Path :",10,182,156,20) $InstallDir = GUICtrlCreateInput("C:\Quick NIC", 80, 180, 156, 20) GUISetState(@SW_SHOW) While 1 $Inst_Message = GUICtrlRead($InstallDir) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Next() ProgressOn("Quick NIC install Progress", "Installing Please wait....", "0 percent") For $i = 0 to 100 step 1 sleep(100) ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "Complete") sleep(500) DirCreate ($Inst_Message & "\Icons") FileInstall ( "C:\IP-Changer\Final App\Icons\proxy.ico", $Inst_Message & "\Icons\proxy.ico",1) FileInstall ( "C:\IP-Changer\Final App\Icons\TarjetadeRed.ico", $Inst_Message & "\Icons\TarjetadeRed.ico",1) FileInstall ( "C:\IP-Changer\Final App\Icons\QuickNICLogo.gif", $Inst_Message & "\Icons\QuickNICLogo.gif",1) FileInstall ( "C:\IP-Changer\Final App\Icons\QuickNICLogoVert.gif", $Inst_Message & "\Icons\QuickNICLogoVert.gif",1) FileInstall ( "C:\IP-Changer\Final App\Quick NIC.exe", $Inst_Message & "\Quick NIC.exe",1) FileInstall ( "C:\IP-Changer\Final App\proxy.ini", $Inst_Message & "\proxy.ini",1) FileInstall ( "C:\IP-Changer\Final App\Ships.ini", $Inst_Message & "\Ships.ini",1) FileInstall ( "C:\IP-Changer\Final App\power.ini", $Inst_Message & "\power.ini",1) FileCreateShortcut($Inst_Message& "\Quick NIC.exe", @DesktopCommonDir & "\Quick NIC.lnk", $Inst_Message, '', 'Qiuck NIC Changer', $Inst_Message & "\Icons\TarjetadeRed.ico", '', '0') RunWait(@ComSpec & ' /c ' & 'cacls "'&$Inst_Message&'\*.*" /e /g "Everyone":F Users:F', "", @SW_HIDE) RunWait(@ComSpec & ' /c ' & 'cacls "'&@DesktopCommonDir&'\Quick NIC.lnk" /e /g "Everyone":F Users:F', "", @SW_HIDE) ProgressOff() sleep(100) If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(68,"Quick NIC install Done","Congratulations," & @CRLF & "You have successfully installed Quick NIC" & @CRLF & "Do you want to run Quick NIC now?" & @CRLF) Select Case $iMsgBoxAnswer = 6 ;Yes Run ("Quick NIC.exe",$Inst_Message) sleep(1000) Exit Case $iMsgBoxAnswer = 7 ;No Exit EndSelect EndFunc Func _Close() Exit EndFunc AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
MHz Posted November 16, 2006 Share Posted November 16, 2006 (edited) 1. Cannot have GUIGetMsg and OnEvent at same time. 2. Use a path for Run() function 3. Use more checking for errors amongst other things. 4. Use expandcollapse popup#include <GUIConstants.au3> #include <File.au3> Opt("GUIOnEventMode", 1) Global Const $Title = 'Quick NIC Changer' Global Const $Version = '3.2.0.1' Global $iMsgBoxAnswer Global $AdminName Global $AdminPass ;CHECK POWER ;=========== If Not IsAdmin() Then $AdminName = InputBox($Title, "Enter local Admin user name:", '', '', 280, 160) If @error Then Exit 1 $AdminPass = InputBox($Title, "Enter local Admin password:", '', '*', 280, 160) If @error Then Exit 2 RunAsSet($AdminName, @ComputerName, $AdminPass) Run('"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '"') Exit EndIf $Form1 = GUICreate("Quick NIC Intaller", 255, 250, -1, -1) $Close = GUICtrlCreateButton("Cancel", 10, 220, 75, 25, 0) GUICtrlSetOnEvent($Close, "_Close") $Next = GUICtrlCreateButton("Next", 170, 220, 75, 25, 0) GUICtrlSetOnEvent($Next, "_Next") $Group1 = GUICtrlCreateGroup("Welcome to Quick NIC installer", 10, 10, 235, 155) $Label1 = GUICtrlCreateLabel('This application is a utility for easily changing your ' & _ 'TCP/IP settings of your Local Area Network and Wireless Network connections.' & @LF & _ 'It also includes a built in tool to change you Proxy setting.' & @LF & _ @LF & _ 'Select a folder to install to or leave it to default' & @LF & _ 'Then click Next', 20, 30, 220, 120) GUICtrlCreateGroup("", -99, -99, 1, 1) $Label1 = GUICtrlCreateLabel("Install Path :", 10, 182, 156, 20) $InstallDir = GUICtrlCreateInput("C:\Quick NIC", 80, 180, 156, 20) GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Cannot have GUIGetMsg and OnEvent at same time. ;~ $nMsg = GUIGetMsg() ;~ Switch $nMsg ;~ Case $GUI_EVENT_CLOSE ;~ Exit ;~ EndSwitch WEnd Func _Next() $Inst_Message = GUICtrlRead($InstallDir) ; Check if the path is available to use use If $Inst_Message = '' Or $Inst_Message = 'Require a Path' Then Return GUICtrlSetData($InstallDir, 'Require a Path') EndIf ; Check for trailing backslash and remove if needed If StringRight($Inst_Message, 1) = '\' Then $Inst_Message = StringTrimRight($Inst_Message, 1) EndIf ProgressOn("Quick NIC install Progress", "Installing Please wait....", "0 percent") For $i = 0 To 100 Step 1 Sleep(100) ProgressSet($i, $i & " percent") Next ProgressSet(100, "Done", "Complete") Sleep(500) DirCreate($Inst_Message & "\Icons") FileInstall("C:\IP-Changer\Final App\Icons\proxy.ico", $Inst_Message & "\Icons\proxy.ico", 1) FileInstall("C:\IP-Changer\Final App\Icons\TarjetadeRed.ico", $Inst_Message & "\Icons\TarjetadeRed.ico", 1) FileInstall("C:\IP-Changer\Final App\Icons\QuickNICLogo.gif", $Inst_Message & "\Icons\QuickNICLogo.gif", 1) FileInstall("C:\IP-Changer\Final App\Icons\QuickNICLogoVert.gif", $Inst_Message & "\Icons\QuickNICLogoVert.gif", 1) FileInstall("C:\IP-Changer\Final App\Quick NIC.exe", $Inst_Message & "\Quick NIC.exe", 1) FileInstall("C:\IP-Changer\Final App\proxy.ini", $Inst_Message & "\proxy.ini", 1) FileInstall("C:\IP-Changer\Final App\Ships.ini", $Inst_Message & "\Ships.ini", 1) FileInstall("C:\IP-Changer\Final App\power.ini", $Inst_Message & "\power.ini", 1) FileCreateShortcut($Inst_Message & "\Quick NIC.exe", @DesktopCommonDir & "\Quick NIC.lnk", $Inst_Message, '', 'Qiuck NIC Changer', $Inst_Message & "\Icons\TarjetadeRed.ico", '', '0') RunWait(@ComSpec & ' /c ' & 'cacls "' & $Inst_Message & '\*.*" /e /g "Everyone":F Users:F', "", @SW_HIDE) RunWait(@ComSpec & ' /c ' & 'cacls "' & @DesktopCommonDir & '\Quick NIC.lnk" /e /g "Everyone":F Users:F', "", @SW_HIDE) ProgressOff() Sleep(100) If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer $iMsgBoxAnswer = MsgBox(68, "Quick NIC install Done", "Congratulations," & @CRLF & "You have successfully installed Quick NIC" & @CRLF & "Do you want to run Quick NIC now?" & @CRLF) Select Case $iMsgBoxAnswer = 6 ;Yes Run('"' & $Inst_Message & '\Quick NIC.exe"', $Inst_Message) Sleep(1000) Exit Case $iMsgBoxAnswer = 7 ;No Exit EndSelect EndFunc I have not fully covered point 3 which you can spend time on. Edit: Added double quotes in Run() function to protect against possible spaces in path. Edited November 16, 2006 by MHz Link to comment Share on other sites More sharing options...
craigholohan Posted November 17, 2006 Author Share Posted November 17, 2006 Hi Guys, Just want to say thanks for all the help I have recieved with this little project, really appreciate it. I think I have more or less what I was aiming for and it seems to work fine. MHz thanks for the help and advice, I will try to concentrat on error checking when I think of something else I need and and start writing it but for this one I am to affraid to mess with it now. One other thing if it is not going to be too difficult I was thinking of encrypting the password that get written to an INI file but it must also be able to be decrypted by the app so a user can run the script in admin mode, so any simple methodes will be well recieved. Anyway thanks again, Craig 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