Sign in to follow this  
Followers 0
Chimaera

Ownership And Permissions question

28 posts in this topic

im knocking together a little attribute and permissions GUI

basically for customer drives that have been caught with the latest security virus that hides everything and changes stuff

starting with

$source = FileSelectFolder("Select Drive" , "")

so the attrib section is done basically just using

FileSetAttrib( $source & "Users", "-H", 1); basically just unhides the folder Users and sub folders

now on the permssion side i have used

RunWait(@ComSpec & "/c" & 'takeown /f $source & "*.*"'); equivalent to C:\*.* if C were chosen
RunWait(@ComSpec & "/c" & 'ICALCS $source & "*.*" /grant @UserName:F'); equivalent to C:\*.* grant current logged on user full permissions

1: So first question is this the right way to do this?

2: I have hit a snag because with file select folder if i click C drive it gives a result of C:\

but if i select c:\users folder it gives a result of C:\Users with no backslash

How do i get it to either add the backslash for all selections with FileSelectFolder

So i get

C:\ or

C:\Users\

so that *.* fits on the end of either

Or is there a way to just get the drive letter and ill add the rest like this & :\ &

Hope this makes sense

Chimaera

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Thanks JohnOne

I ended up with this

$var = StringRight( $source, 1)
if $var = "\" Then 
$source = StringTrimRight( $source , 1) 
EndIf

Chimaera

Edited by Chimaera

Share this post


Link to post
Share on other sites

Or my old favorite

$Source = StringRegExpReplace($Source, "\134*$", "\\", 1)

It will add \ if it's not there and it will replace single or multiple occurences like \\ but only at the end of the string.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

And another I found whilst searching in File.au3, just check out _GetDirectoryFormat() in my Signature.


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Or my old favorite

$Source = StringRegExpReplace($Source, "\134*$", "\\", 1)

It will add \ if it's not there and it will replace single or multiple occurences like \\ but only at the end of the string.

And the winner is GEOSoft, i have no idea "how" it does it but very clever

Thanks for the help

Chim

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Can someone advise on if i have got these laid out correctly plz

Starting with

$source = FileSelectFolder("Select Drive", "C:") ;<<< just for eg
$source = StringRegExpReplace($source, "\134*$", "\\", 1) ;<<< just for eg

Giving me C:\ for eg

Then

RunWait(@ComSpec & "/c takeown /f" & $source & "/r") ;<<< is the syntax correct?

RunWait(@ComSpec & "/c ICALCS" & $source & "*.*" & "/grant @UserName:F") ;<<< is the syntax correct?

As far as i can tell its correct but doesn't seem to work, well it finishes far too quick

can someone just check it for me plz

Many thanks

Edited by Chimaera

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I haven't check on the executable syntax but I know you're missing spaces on before and after the quotes. I also recommend using single quote and put double quotes around $source for the long file names.

RunWait(@ComSpec & " /c takeown /f " & $source & " /r");
RunWait(@ComSpec & " /c ICALCS " & $source & " *.*" & " /grant @UserName:F");

- joon

Edited by Joon

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

aah getting closer it opened a cmd window but just sat there with the cursor in the corner.

if i do it manually like this in a cmd window

takeown /f C:\ /r

it works fine Edited by Chimaera

Share this post


Link to post
Share on other sites

aah getting closer it opened a cmd window but just sat there with the cursor in the corner.

if i do it manually like this in a cmd window

it works fine

hmm... can you change your code to something like this and see the console output?

$syntax = " /c takeown /f " & $source & " /r"
ConsoleWrite($syntax & @LF)
RunWait(@ComSpec & $syntax);

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Here you go all seems to be correct and copied from console

/c takeown /f C:\ /r

and again window open with no text and cursor sat in corner

Edited by Chimaera

Share this post


Link to post
Share on other sites

Here you go all seems to be correct and copied from console

and again window open with no text and cursor sat in corner

This works for me without a problem.

$syntax = " /c takeown /f C:\temp /r"
ConsoleWrite($syntax & @LF)
RunWait(@ComSpec & $syntax)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

This works for me without a problem.

$syntax = " /c takeown /f C:\temp /r"
ConsoleWrite($syntax & @LF)
RunWait(@ComSpec & $syntax)

Ok i cant see what the hell is wrong here. Edited by Chimaera

Share this post


Link to post
Share on other sites

Your code worked on me without any modification. Windows 7 Enterprise x64.

Share this post


Link to post
Share on other sites

You could be running into a permissions problem

try adding " /d y" to the end of $syntax

Also I don't remember what happens if you attempt takeown on a folder where you already have ownership. I've been playing with takeown in some code of mine and it works fine.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

So the Permissions button didnt give a blank window?, im on same OS as you m8

Another odd thing for me, when the blank cmd is open you can press enter and the cursor moves down a line??

EDIT

after addy GEOSoft addition it now flashes the cmd window and exits, ill have to test it on a machine where the ownership is different

to see whats happening

Thanks for the help

Edited by Chimaera

Share this post


Link to post
Share on other sites

Just a hint: you can also use SubInACL to change ownership of files and folders.

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Just a hint: you can also use SubInACL to change ownership of files and folders.

Br,

UEZ

Thanks UEZ

but...

i messed with it a few years ago and its far to complicated for me to use, whilst i agree its the most powerfull but the help is also limited

and i have no idea how to start it through autoit :huh2:

And it dosent seem to support Vista or above on the page you mentioned

Edited by Chimaera

Share this post


Link to post
Share on other sites

This works for me without a problem.

$syntax = " /c takeown /f C:\temp /r"
ConsoleWrite($syntax & @LF)
RunWait(@ComSpec & $syntax)

The cmd window flashes for me on Win7 HomePremium 64-bit

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

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  
Followers 0