How to delete a file from Program Files folder or launch a shortcut file (.lnk) or execute batch file with admin privilage

How to delete a file from Program Files folder or launch a shortcut file (.lnk) or execute batch file with admin privilage

EATREVITPOOPCAD
Collaborator Collaborator
815 Views
2 Replies
Message 1 of 3

How to delete a file from Program Files folder or launch a shortcut file (.lnk) or execute batch file with admin privilage

EATREVITPOOPCAD
Collaborator
Collaborator

Ok, so what I am trying to do is very simple, however, which ever way I approach it I am having issues...

 

I want to delete the file called acad.lsp located in C:\Program Files\Autodesk\AutoCAD 2023\Support\

 

I tried (vl-file-delete) but that fails. I assume AutoCAD wont let you do that...

(vl-file-delete "C:\\Program Files\\Autodesk\\AutoCAD 2023\\Support\\acad.lsp")

 

 

So then I decided to try workarounds... I can make a .BAT file to delete acad.lsp and then launch it with AutoLisp

 

Delete_acad_lsp.bat file looks like this

del "C:\Program Files\Autodesk\AutoCAD 2023\Support\acad.lsp"

 

 

And in AutoLisp I can launch it like this, however, I get access denied because it needs to be run with admin privileges

(startapp "C:\\Program Files\\Autodesk\\AutoCAD 2023\\Support\\Delete_acad_lsp.bat")

 

So then I decided to make a shortcut pointing to Delete_acad_lsp.bat with administrative privileges. However (startapp) doesn't work on shortcut files...

(startapp "C:\\Users\\Public\\Desktop\\Delete_acad_lsp.lnk")

 

 

Any ideas on how I can do this?: I don't care how, I just want to delete acad.lsp from an autolisp routine launched from AutoCAD

 

 

The definition of insanity is doing the same thing over and over again and expecting different results
0 Likes
Accepted solutions (1)
816 Views
2 Replies
Replies (2)
Message 2 of 3

Moshe-A
Mentor
Mentor

@EATREVITPOOPCAD ,

 

right click AutoCAD shortcut and pick run as administrator, does that solve the issue?

 

Moshe

 

 

 

0 Likes
Message 3 of 3

EATREVITPOOPCAD
Collaborator
Collaborator
Accepted solution

Yes, I did that to the shortcut. However, I couldn't figure out how to launch the shortcut using Autolisp from AutoCAD.

 

Anyway call me a madman, but this is how I solved the issue. I created another batch file to call that shortcut which calls my delete batch script with administrative privileges LOL

The definition of insanity is doing the same thing over and over again and expecting different results
0 Likes