dantay9 Posted April 30, 2009 Share Posted April 30, 2009 I am currently trying to make a script which will lock a usb drive without a password using user permissions. I am trying to run a command in cmd from the SYSTEM account to lock and unlock the drive. It works when I enter it manually, but it doesn't work when I try to put it in a bat file. Why doesn't this work? expandcollapse popup$Box = InputBox("Password Verification", "Please enter your password.", "", "*") If $Box = "password" Then SYSTEM_Login() $sFile = 'C:\test.bat' $sText = 'CACLS "K:" /E /T /C /P "Owner":F';or "Owner":N $tBuffer = DllStructCreate("byte[" & StringLen($sText) & "]") DllStructSetData($tBuffer, 1, $sText) $hFile = _WinAPI_CreateFile($sFile, 1) _WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer), StringLen($sText), $nBytes) _WinAPI_CloseHandle($hFile) $Process = ShellExecute($sFile) ConsoleWrite($Process & @CRLF) While ProcessExists($Process) Sleep(1000) WEnd ProcessClose("explorer.exe") ProcessWaitClose("explorer.exe") Run("explorer.exe") EndIf Func SYSTEM_Login() Dim $objWMIsrvc, $objItem, $objSrvc Dim $SrvcList, $strSrvc $objSrvcs = ObjGet("winmgmts:root\cimv2") $objSrvc = $objSrvcs.Get("Win32_Service") $objParams = $objSrvc.Methods_("Create") .inParameters.SpawnInstance_() $objParams.Properties_.item("Name") = "SYSTEMSHIFT" $objParams.Properties_.item("DisplayName") = "SYSTEMSHIFT" $objParams.Properties_.item("PathName") = "C:\WINDOWS\system32\cmd.exe /c C:\WINDOWS\explorer.exe" $objParams.Properties_.item("ServiceType") = 16 $objParams.Properties_.item("ErrorControl") = 0 $objParams.Properties_.item("StartMode") = "Manual" $objParams.Properties_.item("DesktopInteract") = True $objOutParams = $objSrvc.ExecMethod_("Create", $objParams) ConsoleWrite($objOutParams) RunWait(@ComSpec & " /c taskkill /F /IM explorer.exe", '', @SW_HIDE) $strSrvc = "SYSTEMSHIFT" $objWMIsrvc = ObjGet("winmgmts:root\cimv2") $SrvcList = $objWMIsrvc.ExecQuery("Select * from Win32_Service Where Name = '" & $strSrvc & "'") For $objSrvc In $SrvcList $objSrvc.StartService() Sleep(100) $objSrvc.StopService() $objSrvc.Delete() Next EndFunc ;==>SYSTEM_Login Link to comment Share on other sites More sharing options...
dantay9 Posted May 1, 2009 Author Share Posted May 1, 2009 If this is not possible, I am open to other ideas about how to lock the usb drive and also be able to unlock it. Link to comment Share on other sites More sharing options...
dantay9 Posted May 1, 2009 Author Share Posted May 1, 2009 Maybe my question wasn't open enough. I have a usb drive (a whole drive) that I want to lock. What is the best way of doing this? Link to comment Share on other sites More sharing options...
Yashied Posted May 1, 2009 Share Posted May 1, 2009 (edited) $sText = 'CACLS "K:" /E /T /C /P "Owner":F'What this "CACLS"?Move this file to Windows\System32 folder or write a path to this file (for example "C:\MyCacls\CACLS.EXE" "K:" /E /T /C /P "Owner":F).Also read this. EDIT: The code you have works in the form in which you presented it here? Say? $nBytes must be declared? And where #Include <WinAPI.au3>. Edited May 1, 2009 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... 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