africanism Posted February 26, 2010 Share Posted February 26, 2010 Hello to all I would like to create a script to add the user in the admin localgroup based so are pc and are user are referenced in an Excel file. gender if the name of the pc and the user are referenced in a file it executes the script otherwise it is a message that there is no reference in the file admin rights. Can you enlighten me on how to follow. sorry for my EnglishAdmin.zip Link to comment Share on other sites More sharing options...
notsure Posted February 26, 2010 Share Posted February 26, 2010 (edited) shell "%comspec% /c net user name password /add" shell "%comspec% /c net localgroup administrators name /add" Edited February 26, 2010 by notsure Link to comment Share on other sites More sharing options...
africanism Posted February 26, 2010 Author Share Posted February 26, 2010 My script #include <GUIConstants.au3> $filename = FileOpen("admin.xls", 0) $user = InputBox('Utilisateur', "Login ex:DOMAIN\User1") RunAs(administrator, @ComputerName, password, 0, @ComSpec, @SystemDir) RunWait(@ComSpec & ' /c net localgroup Administrators /add ' & FileReadLine($filename, 1), @SystemDir, @SW_HIDE) joint file excel thanksAdmin.zip Link to comment Share on other sites More sharing options...
notsure Posted February 26, 2010 Share Posted February 26, 2010 My script #include <GUIConstants.au3> $filename = FileOpen("admin.xls", 0) $user = InputBox('Utilisateur', "Login ex:DOMAIN\User1") RunAs(administrator, @ComputerName, password, 0, @ComSpec, @SystemDir) RunWait(@ComSpec & ' /c net localgroup Administrators /add ' & FileReadLine($filename, 1), @SystemDir, @SW_HIDE) joint file excel thanks Try Excel UDF? $oExcel = _ExcelBookAttach("admin.xls", "FileName"); attach excel if $oExcel = -1 Then msgbox(16,"Error", "Cant open admin.xls") EndIf for $i = 1 to 10 $user = _ExcelReadCell($oExcel, $i, 2);$oExcel = Instance, $i = row, 2 is column. ;your ;code ;here ;etc. Next Link to comment Share on other sites More sharing options...
africanism Posted February 26, 2010 Author Share Posted February 26, 2010 thanks but my code is not correct please #include <GUIConstants.au3> $filename = FileOpen("c:\admin.xls", 0) $user = InputBox('Utilisateur', "Login ex:Domain\*****") $oExcel = _ExcelBookAttach("c:\admin.xls", "admin"); attach excel If $oExcel = -1 Then MsgBox(16, "Error", "Cant open admin.xls") EndIf For $i = 1 To 10 $user = _ExcelReadCell($oExcel, $i, 2);$oExcel = Instance, $i = row, 2 is column. RunAs("administrator", @ComputerName, "123456", 0, @ComSpec, @SystemDir) RunWait(@ComSpec & ' /c net localgroup Administrators /add ' & $user, @SystemDir, @SW_HIDE) Next Link to comment Share on other sites More sharing options...
africanism Posted March 1, 2010 Author Share Posted March 1, 2010 please Link to comment Share on other sites More sharing options...
notsure Posted March 1, 2010 Share Posted March 1, 2010 @Computername must be Domain in the RunAs... i cannot test it here coz i dont have admin rights on the PC i am working at right now. Link to comment Share on other sites More sharing options...
99ojo Posted March 1, 2010 Share Posted March 1, 2010 Hi, try: RunAsWait("administrator", @ComputerName, "123456", 0, @ComSpec & ' /c net localgroup Administrators /add ' & $user, @SystemDir, @SW_HIDE) instead of: RunAs("administrator", @ComputerName, "123456", 0, @ComSpec, @SystemDir) RunWait(@ComSpec & ' /c net localgroup Administrators /add ' & $user, @SystemDir, @SW_HIDE) ;-)) Stefan Link to comment Share on other sites More sharing options...
africanism Posted March 1, 2010 Author Share Posted March 1, 2010 hi Well I just managed as best I could. Here are the script #include <Excel.au3> #include <GUIConstants.au3> ;Popup User $user = InputBox('Utilisateur', "Login ex:DOMAIN\*****") RunAs("administrator", @ComputerName, "123456", 0, @ComSpec, @SystemDir) ProgressOn("LocalGroup_Admin_Install", "Progression", "0 %") For $i = 0 To 100 Step 100 Sleep(500) ProgressSet($i, $i & " %") $sFilePath1 = "c:\admin.xls" Local $oExcel = _ExcelBookOpen($sFilePath1) ; Recherche Local $search_keyword = @ComputerName & "\" & $user Local $search_cell = $oExcel.Columns("A" ).Find($search_keyword) If (IsObj($search_cell) = 1) Then ; Si la recherche à abouti MsgBox(0, "Find success", "La recherche de " & Chr(34) & $search_keyword & Chr(34) & " dans la plage donne la cellule (" & $search_cell.Row & ";" & $search_cell.Column & ")") Run(@ComSpec & ' /c net localgroup Administrateurs /add ' & $user, @SystemDir, @SW_HIDE) Else MsgBox(0, "Find failed", "La recherche de " & Chr(34) & $search_keyword & Chr(34) & " dans la plage n'a rien donné") EndIf Next ProgressSet(100, "Fini", "Complet") Sleep(500) ProgressOff() FileClose($sFilePath1) if the attached excel file. 2 quick question? I have a back window that opens and I know why is it possible to check the excel file without opening it. if possible do not how to close excel file with verification of info inside. CdtAdmin.zip Link to comment Share on other sites More sharing options...
kaotkbliss Posted March 1, 2010 Share Posted March 1, 2010 _ExcelBookOpen("path to excel file",0) the 0 sets the book to invisible so you will not see excel when it opens but you can still work with it. need to add #include<Excel.au3> to begining of script. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
africanism Posted March 1, 2010 Author Share Posted March 1, 2010 tks thank you is what I needed I question why the popup that launches 2 times Link to comment Share on other sites More sharing options...
africanism Posted March 3, 2010 Author Share Posted March 3, 2010 Hello im change ma script it's ok but after the script is run it and close. 2 excel.exe process remains open why? ;Popup User $user = InputBox('Utilisateur', "Login ex:domain\*****", "domain\") If $user <> "" Then ProgressOn("LocalGroup_Admin_Install", "Progression", "0 %") For $i = 0 To 100 Step 100 Sleep(500) ProgressSet($i, $i & " %") $sFilePath1 = "\\server\folder\folder1\Droit_admin\admin.xls" $oExcel = _ExcelBookOpen($sFilePath1, 0) ; Recherche $search_keyword = @ComputerName & "\" & $user $search_cell = $oExcel.Columns("A" ).Find($search_keyword) If (IsObj($search_cell) = 1) Then ; Si la recherche à abouti RunAsWait("administrator", @ComputerName, "123456", 0, @ComSpec & ' /c net localgroup Administrators /add ' & $user, @SystemDir, @SW_HIDE) MsgBox(4096, "Derogation", "Votre compte " & $user & " est maintenant admin du poste pensez a fermer la session pour prendre en compte la demande") Else MsgBox(4096, "Derogation", "La recherche de " & $user & " dans le fichier de derogation n'existe pas") EndIf Next ProgressSet(100, "Fini", "Complet") Sleep(500) ProgressOff() FileClose($sFilePath1) $oExcel = _ExcelBookClose($sFilePath1, 0) EndIf Link to comment Share on other sites More sharing options...
99ojo Posted March 3, 2010 Share Posted March 3, 2010 (edited) Hi, see helpfile: _ExcelBookClose -------------------------------------------------------------------------------- Closes the active workbook and removes the specified Excel object. #Include <Excel.au3> _ExcelBookClose($oExcel [, $fSave = 1 [, $fAlerts = 0]]) Parameters $oExcel Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew() $fSave [optional] Flag for saving the file before closing (0=no save, 1=save) (default = 1) $fAlerts [optional] Flag for disabling/enabling Excel message alerts (0=disable, 1=enable) (default = 0) In your case: _ExcelBookClose($oExcel, 0) ;-)) Stefan Edited March 3, 2010 by 99ojo Link to comment Share on other sites More sharing options...
africanism Posted March 3, 2010 Author Share Posted March 3, 2010 thank you but what I have written $oExcel = _ExcelBookClose($sFilePath1, 0 Link to comment Share on other sites More sharing options...
99ojo Posted March 3, 2010 Share Posted March 3, 2010 Hi, i read what you have written. But you have to close the excel object, not the excel file: $sFilePath1 = "\\server\folder\folder1\Droit_admin\admin.xls" $oExcel = _ExcelBookOpen($sFilePath1, 0) ; code whatever _ExcelBookClose($oExcel, 0) ; this call closes excel object $oExcel without saving ;-)) Stefan Link to comment Share on other sites More sharing options...
africanism Posted March 3, 2010 Author Share Posted March 3, 2010 that's ok thanks 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