help me tranform RunProgram to ShellExecute_

Just starting out? Need help? Post your questions and find answers here.
GogaII
User
User
Posts: 29
Joined: Sun Nov 15, 2020 10:03 am

help me tranform RunProgram to ShellExecute_

Post by GogaII »

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?
Olli
Addict
Addict
Posts: 1240
Joined: Wed May 27, 2020 12:26 pm

Re: help me tranform RunProgram to ShellExecute_

Post by Olli »

The dot?

Code: Select all

ShellExecute_(0, "RunAS", "wscript.exe", "//nologo "+Scrip.vbs +" "+DirToDelete$, TempDir$, #SW_SHOWNORMAL)
GogaII
User
User
Posts: 29
Joined: Sun Nov 15, 2020 10:03 am

Re: help me tranform RunProgram to ShellExecute_

Post by GogaII »

Oh, I'm sorry, I wrote '', ' instead of "." only here, not in my real code.
After extra investigations I found out that

Code: Select all

ShellExecute_(0, "RunAS", "wscript.exe", "//nologo "+Scrip.vbs +" "+DirToDelete$, TempDir$, #SW_SHOWNORMAL)
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.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: help me tranform RunProgram to ShellExecute_

Post by RASHAD »

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

Code: Select all

OpenWindow(?,?,?
.
.
Repeat

Until Quit = 1
  RunProgram(GetEnvironmentVariable("comspec"),"/c del "+Chr(34)+ProgramFilename()+Chr(34),"",2)
Egypt my love
GogaII
User
User
Posts: 29
Joined: Sun Nov 15, 2020 10:03 am

Re: help me tranform RunProgram to ShellExecute_

Post by GogaII »

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.
Marc56us
Addict
Addict
Posts: 1600
Joined: Sat Feb 08, 2014 3:26 pm

Re: help me tranform RunProgram to ShellExecute_

Post by Marc56us »

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)

:wink:
Post Reply