Jump to content

Access Permissions


Recommended Posts

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
Link to comment
Share on other sites

$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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...