Alphaz Posted May 17, 2006 Share Posted May 17, 2006 Hi,I would like to know how I can create a script to run a program as the administrator, from a different user account, by encrypting the password in the batch file I will create.For example, in my company, the users don't have admin rights on their PC, so they can't defragment their hard drives or empty a specific folder on the hard drive...Any idea on how to do it? I know I can encrypt the admin password in an unattended install of windows, but for my need I don't see how to do it.Thanks in advance for your help.RegardsTitle edited -- Please, use [TAGS] in your topic's title.--Sonic Link to comment Share on other sites More sharing options...
Sonic Posted May 17, 2006 Share Posted May 17, 2006 You can't hide/crypt admin password in a simple .cmd file, except with use credential but you must have to enter once the password in clear.Compiled VBS can be used I think, wait a moment for masters of vbs ^^ Link to comment Share on other sites More sharing options...
cluberti Posted May 17, 2006 Share Posted May 17, 2006 Hiding the contents of your script can be done once your vbscript is complete via the Microsoft Script Encoder:http://www.microsoft.com/downloads/details...&displaylang=enAs to using runas in the script, the following simple 4 lines will work:set WshShell = CreateObject("WScript.Shell")WshShell.Run "runas /user:User ""C:\runsomething.cmd"""WScript.Sleep 100WshShell.Sendkeys "password"It can be done much cleaner, but the above is an easy 4 lines, and it's a start. Link to comment Share on other sites More sharing options...
Alphaz Posted May 17, 2006 Author Share Posted May 17, 2006 Hiding the contents of your script can be done once your vbscript is complete via the Microsoft Script Encoder:http://www.microsoft.com/downloads/details...&displaylang=enAs to using runas in the script, the following simple 4 lines will work:set WshShell = CreateObject("WScript.Shell")WshShell.Run "runas /user:User ""C:\runsomething.cmd"""WScript.Sleep 100WshShell.Sendkeys "password"It can be done much cleaner, but the above is an easy 4 lines, and it's a start.Hello,Thanks for the above, it leads me close to what i want to do, but i copied the lines above and it still prompts me for the passord<script LANGUAGE="VBScript">'Copyright© 1998. XYZ Productions. All rights reserved.'**Start Encode**' Your code goes here.set WshShell = CreateObject("WScript.Shell")WshShell.Run "runas /user:USERNAME ""del c:\test.txt"""WScript.Sleep 100WshShell.Sendkeys "PASSWORD_OF_USER_ABOVE"</SCRIPT> Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 17, 2006 Share Posted May 17, 2006 Here is a link to a article on how to uae the run as in a script. If you use the encoder then the script will be encoded and harder to edit.Hey, Scripting Guy! Link to comment Share on other sites More sharing options...
Alphaz Posted May 17, 2006 Author Share Posted May 17, 2006 Obviously, if i send the password after running the command, it can't work... If I put the following belowWshShell.Run "runas /user:USERNAME ""del c:\test.txt"""WScript.Sleep 100WshShell.Sendkeys "PASSWORD_OF_USER_ABOVE"WshShell.Run "del c:\test.txt"Any idea why the file is not deleted ? Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 17, 2006 Share Posted May 17, 2006 Obviously, if i send the password after running the command, it can't work... If I put the following belowWshShell.Run "runas /user:USERNAME ""del c:\test.txt"""WScript.Sleep 100WshShell.Sendkeys "PASSWORD_OF_USER_ABOVE"WshShell.Run "del c:\test.txt"Any idea why the file is not deleted ?You cannot delete the file because you are using the wrong object for it.The changes I made are This means the window is hidden and it will not go on to the next until it finished1:\ WshShell.Run "runas /user:USERNAME", 0, True Added the correct object to delete the file2:\ Set Fso = CreateObject("Scripting.FileSystemObject")Change the File name to a varible 3:\ File = "c:\test.txt"'/--> Varibles Dim Fso, File, WshShell'/--> Varibles As Objects Set WshShell = Createobject("Wscript.Shell") Set Fso = CreateObject("Scripting.FileSystemObject") File = "c:\test.txt" WshShell.Run "runas /user:USERNAME", 0, True WshShell.Sendkeys "PASSWORD_OF_USER_ABOVE"'/--> Checks For The File Then If It Exists It deletes It If Fso.FileExists(File) Then Fso.DeleteFile(File) End If Link to comment Share on other sites More sharing options...
TheFlash428 Posted May 17, 2006 Share Posted May 17, 2006 not much to add, but thanks a lot for the tips. I think reading this post has given me the idea on how to solve one of my problems! Link to comment Share on other sites More sharing options...
firefoxthebomb Posted May 17, 2006 Share Posted May 17, 2006 good question, it will also help me in solving one of my issues that I have as well, thanks for all the good information. Link to comment Share on other sites More sharing options...
Alphaz Posted May 18, 2006 Author Share Posted May 18, 2006 '/--> Varibles Dim Fso, File, WshShell'/--> Varibles As Objects Set WshShell = Createobject("Wscript.Shell") Set Fso = CreateObject("Scripting.FileSystemObject") File = "c:\test.txt" WshShell.Run "runas /user:USERNAME", 0, True WshShell.Sendkeys "PASSWORD_OF_USER_ABOVE"'/--> Checks For The File Then If It Exists It deletes It If Fso.FileExists(File) Then Fso.DeleteFile(File) End IfThat's fantastic, thanks a million for your help With the script encoder from MS I can distribute the file to whoever I want and they won't see the admin password I have another question: What kind of objet I have to create to empty a folder? If i replace File = "c:\test.txt" byt File = "c:\*.txt", the script does not delete the files in my folder.Alphaz Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 18, 2006 Share Posted May 18, 2006 '/--> Varibles Dim Fso, File, WshShell'/--> Varibles As Objects Set WshShell = Createobject("Wscript.Shell") Set Fso = CreateObject("Scripting.FileSystemObject") File = "c:\test.txt" WshShell.Run "runas /user:USERNAME", 0, True WshShell.Sendkeys "PASSWORD_OF_USER_ABOVE"'/--> Checks For The File Then If It Exists It deletes It If Fso.FileExists(File) Then Fso.DeleteFile(File) End IfThat's fantastic, thanks a million for your help With the script encoder from MS I can distribute the file to whoever I want and they won't see the admin password I have another question: What kind of objet I have to create to empty a folder? If i replace File = "c:\test.txt" byt File = "c:\*.txt", the script does not delete the files in my folder.AlphazVBS does not accept wild cards but here a script that should in theory should delete all the text filesAll you have to do is make sure that Dim FolderName : FolderName = "C:\" the Green text is the correct Drive this also can be "C:\Some_Folder"'/-> Varible And Objects Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim Act : Set Act = CreateObject("Wscript.Shell")'/-> Binds The Folder Or Drive For Collection Dim FolderName : FolderName = "C:\" '/-> Binds To The Drive Or Folder Dim objFolder : Set objFolder = Fso.GetFolder(FolderName) Dim collectFiles : Set collectFiles = objFolder.Files'/-> This is The New Varible Name For The Loop Dim objFile'/-> This Start A Loop That Collects All The Files In FolderName For Each objFile in collectFiles'/-> This Checks For The Extention txt or TXT or Txt This Is Not Case Sensitive If InStr(objFile.Name,"txt") Then Fso.DeleteFile(objFile.Path) End If Next Link to comment Share on other sites More sharing options...
net_user Posted May 18, 2006 Share Posted May 18, 2006 shouldn't this be in the programming forum? Link to comment Share on other sites More sharing options...
gunsmokingman Posted May 18, 2006 Share Posted May 18, 2006 shouldn't this be in the programming forum?No since it question about Windows XP. and since a mod replied already then it is in the correct form. You can't hide/crypt admin password in a simple .cmd file, except with use credential but you must have to enter once the password in clear.Compiled VBS can be used I think, wait a moment for masters of vbs ^^ Link to comment Share on other sites More sharing options...
LLXX Posted May 18, 2006 Share Posted May 18, 2006 Attempting to "hide" the password is futile, as I demonstrated a long time ago by recovering the password stored in a compiled AutoIt script (actually, the entire script, complete with comments and formatting) within a few minutes. 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