8
Did not want to run the entire program with administrator privilege, for security reasons and for convenience.
However I need to execute a command:
exec.Command(`cmd`, `/c`, `CheckNetIsolation.exe`, `LoopbackExempt`, `-a`, `-n=....`)
This ONLY works when the program opens "as an administrator". That is, I have open the meu-programa.exe
as administrator for the command to work. Without this, it results in an error.
The entire program runs without administrator permission, EXCEPT for this code above. It is the only command that requires this privilege.
It doesn’t make much sense to have to open as an administrator just because of a single line of code, and everything would work without it.
Is there any way to JUST require the administrator to execute that command? That is, something like (that doesn’t exist!):
exec.Command(`cmd`, `/c`, `/admin`, `....`)
That is, the /admin
would appear that "screen" requesting the user authorization to run as administrator... Anyway, the entire program would still be without the privileges and only this command would be executed as administrator.
Is there anything like?
I have noticed that some programs, during execution and at some random time, require you to grant administrator permission. How this is done is something similar to this case?
Note: The entire program is only one .exe
, without .dll
or others .exe
or related. I can even include other files (such as a .bat
) and extract it at runtime, but I don’t know if it’s a good way, but it might ease the process.
I just looked over, see if there’s any... https://stackoverflow.com/questions/31558066/how-to-ask-for-privileges-administeron-windows-with-go
– MagicHat
There is the possibility to open this program with powershell
– Augusto Vasques
I believe that these other programs have inside them mini-programs or else it is installed together, being internal is "extracted" (or generated) in the TMP of the operating system and probably run using the start command (https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/start) to run as admin (to request the UAC), the PAI programme, must have a communication signal with the "son" (the extracted one), the father probably expects a signal from the son, and the child shut down arbitrarily it also detects. Finally, this sign should be a simple "socket" or even a file.
– Guilherme Nascimento
I think that already gives you a north of how to develop something.
– Guilherme Nascimento
His 'Note' does not correspond to what is practiced, even because Rust and Go language that are modern have interoperability with C/C++ and Wrappers. Go has the default syscall library, to load Dlls and so make calls. In complex and coherent projects divide to conquer, for analogy, the layers of TCP/IP networks were created precisely because it is impossible to do everything together and mixed.
– byteman
@aldison What I emphasize is a single executable, take two clicks and run the application without using installers or other dependencies. It is possible to load Dlls, I did not say it is not. The problem is that if it is not static, it will be necessary to include them within the application (such as
var DLL = []byte{ a dll }
, IN THIS CASE. Then extract it and use thewindows.NewLazyDLL
. This works but continues "a single . exe". So if there are two.exe
, the second would be inside the first (var SegundoEXE = ...
:Q), as @Guilherme Nascimento mentioned. The problem with this is that it looks kind of Overkill.– Inkeliz
@Inkeliz I understand! I made an update on the answer, I realized it’s possible with GOROUTINE, and congratulations on the question.
– byteman
Only one detail, instead of using PHYSICALDRIVE0 would be preferable to use TMP, remember that if you have multiple users accessing the machine, be it two logged in accounts or even one logged in and another "remote" will already have problems, all this requires a attention and will have problems if you do not, so much so that I did not formulate the answer, because it is something that depends on a number of situations.
– Guilherme Nascimento