Hi everybody
Help me please, translate a pb function into an API function
This expression: RunProgram("wscript.exe", "//nologo "+Script.vbs+" "+DirToDelete$, TempDir$ ) is working fine.
But I need to perform the Script.vbs with admin rights.
Unfortunately, I can't transform the RunProgram() into ShellExecute_(), i.e. I'm trying to write
ShellExecute_(0, "RunAS", "wscript.exe", "//nologo "+Scrip,vbs +" "+DirToDelete$, TempDir$, #SW_SHOWNORMAL)
but it doesn't work properly. Could you advice me what I should change here?
help me tranform RunProgram to ShellExecute_
Re: help me tranform RunProgram to ShellExecute_
The dot?
Code: Select all
ShellExecute_(0, "RunAS", "wscript.exe", "//nologo "+Scrip.vbs +" "+DirToDelete$, TempDir$, #SW_SHOWNORMAL)
Re: help me tranform RunProgram to ShellExecute_
Oh, I'm sorry, I wrote '', ' instead of "." only here, not in my real code.
After extra investigations I found out that
working fine too. But only in those directories which don't require admin right. For example it works in some D:\This directory must be deleted\my_program.exe
But when I launch it in c:\Program Files (x86)\This directory must be deleted\my_program.exe it doesn't work
I want my exe-file to delete itself, and for it I try to use an external script.
P.S. I even turned off my antivirus program, but it didn't help too.
After extra investigations I found out that
Code: Select all
ShellExecute_(0, "RunAS", "wscript.exe", "//nologo "+Scrip.vbs +" "+DirToDelete$, TempDir$, #SW_SHOWNORMAL)
But when I launch it in c:\Program Files (x86)\This directory must be deleted\my_program.exe it doesn't work

I want my exe-file to delete itself, and for it I try to use an external script.
P.S. I even turned off my antivirus program, but it didn't help too.
Re: help me tranform RunProgram to ShellExecute_
Hi
Try the next
- Add
RunProgram(GetEnvironmentVariable("comspec"),"/c del "+Chr(34)+ProgramFilename()+Chr(34),"",2)
At the end of the loop
- Compile your code as exe in any folder
- Run your exe
Try the next
- Add
RunProgram(GetEnvironmentVariable("comspec"),"/c del "+Chr(34)+ProgramFilename()+Chr(34),"",2)
At the end of the loop
- Compile your code as exe in any folder
- Run your exe
Code: Select all
OpenWindow(?,?,?
.
.
Repeat
Until Quit = 1
RunProgram(GetEnvironmentVariable("comspec"),"/c del "+Chr(34)+ProgramFilename()+Chr(34),"",2)
Egypt my love
Re: help me tranform RunProgram to ShellExecute_
Thank you, Rashad for your solution. It's working. And first I was happy but then I remembered why I refused to do like that. I couldn't delete the directory in which this file was. I.e. my real situation is: I need to delete both the file itself and its directory. And in this case I was not able to delete the directory using cmd.exe (probably I don't have enough experience with cmd ). In my initial variant I can remove both the file.exe and its directory , but in the case of requirement of admin rights it doesn't work ((
Does anyone have any ideas? Pls, help me.
Does anyone have any ideas? Pls, help me.
Re: help me tranform RunProgram to ShellExecute_
You can proceed as the installation programs do:
1. When you call the uninstaller, it first copies itself to the temporary directory and then starts this copy.
Thus the file handle on the program and on the original directory is freed so can be deleted. User have always write acces to GetTemporaryDirectory().
2. it is normal that a standard user cannot perform commands as an administrator without having the same level of clearance, otherwise anyone could delete anything. Admin rights are rarely needed, just ask your admin for rights to the directories you need. (Create, Delete)

1. When you call the uninstaller, it first copies itself to the temporary directory and then starts this copy.
Thus the file handle on the program and on the original directory is freed so can be deleted. User have always write acces to GetTemporaryDirectory().
2. it is normal that a standard user cannot perform commands as an administrator without having the same level of clearance, otherwise anyone could delete anything. Admin rights are rarely needed, just ask your admin for rights to the directories you need. (Create, Delete)
