Jump to content

Delete File as Admin


 Share

Recommended Posts

I have a user that needs a file deleted but can't remove it himself due to a rights issue. Our SCCM client isn't installed on his machine so I can't just do it myself without physically going there, which I won't be able to do for some time. I'd like to send him a compiled script that will delete it. FileDelete doesn't have any arguments for username and password. I've looked at RunAs but I don't know if that's the answer for what I want either. Would someone point me to the correct function or guide me in using what I've mentioned?

$userName = "mwoods"
$password = "password"

;something in here to give FileDelete permission to run based on my username and password

FileDelete("c:\Novell\Groupwise\gwxl97.xla")
FileDelete("c:\Program Files\Microsoft Office\Office10\XLStart\gwxl97.xla")
FileDelete("c:\Program Files\Microsoft Office\Office12\XLStart\gwxl97.xla")

Thanks.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

Hi!

This is a way:

Func DeleteAs($username, $domain, $password,$logon_flags, $filename)
    RunAs($username, $domain, $password, $logon_flags, @AutoItExe & ' /AutoIt3ExecuteLine  "FileDelete(''' & $filename & ''')"')
EndFunc  ;==>DeleteAs

:mellow:

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

What does /AutoIt3ExecuteLine do?

So should this work?

$username = "mwoods"
$domain   = '@COMPUTER'
$password = "password"
$filePath = "c:\Novell\Groupwise\gwxl97.xla"

RunAs($username, $domain, $password, 0, @AutoItExe & ' /AutoIt3ExecuteLine  "FileDelete($filePath)"')
Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

What does /AutoIt3ExecuteLine do?

So should this work?

$username = "mwoods"
 $domain   = '@COMPUTER'
 $password = "password"
 $filePath = "c:\Novell\Groupwise\gwxl97.xla"
 
 RunAs($username, $domain, $password, 0, @AutoItExe & ' /AutoIt3ExecuteLine  "FileDelete($filePath)"')
/AutoIt3ExecuteLine allows you to run one line of autoit code directly from the command line.

I don't know if your code works (quotes & command lines are tricky) but I know my code does.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Link to comment
Share on other sites

/AutoIt3ExecuteLine allows you to run one line of autoit code directly from the command line.

I don't know if your code works (quotes & command lines are tricky) but I know my code does.

Mine doesn't work. And I'm on my own machine with full rights to everything so I don't even need to run it as admin. I think this means I'm not doing the delete properly. Basically I just tried plugging my stuff into your line but somethign is amiss and I'm not figuring out how to troubleshoot it.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

Interesting. So any compiled AutoIt script can use the /AutoIt3ExecuteLine flag to execute code?

Seems to be the case.

Yeah, that's what I was wondering because this isn't going to be run on a machine that has AutoIt installed.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

  • Developers

Mine doesn't work. And I'm on my own machine with full rights to everything so I don't even need to run it as admin. I think this means I'm not doing the delete properly. Basically I just tried plugging my stuff into your line but somethign is amiss and I'm not figuring out how to troubleshoot it.

It is clear that your code will not work because $filepath is plugged in in stead of the filename, that is why you need to use the original posted script and change it to use the proper variable.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It is clear that your code will not work because $filepath is plugged in in stead of the filename, that is why you need to use the original posted script and change it to use the proper variable.

Jos

Aaaaah. Those quotes were confusing me so I thought that variable would work.

Okay, wait, you are saying I can use a variable. So I guess I don't understand. I think I'm not seeing something you guys are saying should be right in front of my face. I worked the election last night after working my regular shift- my brain is a few throwing stars short of, well, of whatever Kid Niki keeps his throwing stars in.

Edited by muncherw
Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

This doesn't work...but is it closer?

RunAs($username, $domain, $password, 0, @AutoItExe & ' /AutoIt3ExecuteLine  "FileDelete("c:\Documents and Settings\MWoods\desktop\index.html")"')

I'm befuddled by the quotes. At least I t hink it's the quotes that are messing me up.

Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

This doesn't work...but is it closer?

RunAs($username, $domain, $password, 0, @AutoItExe & ' /AutoIt3ExecuteLine  "FileDelete("c:\Documents and Settings\MWoods\desktop\index.html")"')

I'm befuddled by the quotes. At least I t hink it's the quotes that are messing me up.

It's messy, but sometimes I'll use the Chr() func and keycode 34 to write a " in a string.

RunAs($username, $domain, $password, 0, @AutoItExe & ' /AutoIt3ExecuteLine  "FileDelete(' & chr(34) & 'c:\Documents and Settings\MWoods\desktop\index.html' & chr(34) & ')"')
Edited by spudw2k
Link to comment
Share on other sites

Why can't you just use the function that monoceres provided back on post 2?

That's what I'm trying to do. I *want* to use his function. I'm not understanding it.

$username = "mwoods"
$domain   = '@COMPUTER'
$password = "password"
$logon_flags = 0
$filename = "C:\Documents and Settings\mwoods\Desktop\index.html"

DeleteAs($username, $domain, $password, $logon_flags, $filename)

Func DeleteAs($username, $domain, $password, $logon_flags, $filename)
    RunAs($username, $domain, $password, $logon_flags, @AutoItExe & ' /AutoIt3ExecuteLine  "FileDelete(''' & $filename & ''')"')
EndFunc ;==>DeleteAs

I thought I was just plugging in my stuff for his but I guess I was modifying more than I thought.

Edited by muncherw
Other People's Stuff:Andy Flesner's AutoIt v3: Your Quick Guide[topic="34302"]Locodarwin's ExcelCom_UDF[/topic][topic="61090"]MrCreatorR's Opera Library[/topic]
Link to comment
Share on other sites

  • 3 years later...

Try this

$Username = "mwoods"
$domain = @ComputerName
$Password = "password"
$logon_flags = 0
$filename = "C:Documents and SettingsmwoodsDesktopindex.html"



DeleteAs($username, $domain, $password, $logon_flags, $filename)

Func DeleteAs($username, $domain, $password, $logon_flags, $filename)
RunAs($username, $domain, $password, $logon_flags, @AutoItExe & ' /AutoIt3ExecuteLine "FileDelete(''' & $filename & ''')"')
EndFunc ;==>DeleteAs
Edited by grtech
Link to comment
Share on other sites

  • Moderators

grtech,

Why did you post exactly the same code as monoceres had already posted 4 years ago? :wacko:

Please do not necro-post like this. :naughty:

M23

P.S. The question is rhetorical - please do not respond.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Appologies if it looks the same put it is not exactly the same, there is a slight mistake and i corrected, as i have got it working, i thought that i would update the post so that everyone who did a search on it could also get the code to work.

Thanks

GRTech

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...