Jump to content
Sign in to follow this  
dantay9

Access Permissions

Recommended Posts

dantay9

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?

$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

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
dantay9

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.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
dantay9

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?


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites
Yashied

$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 by Yashied

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.