Comments (6)
Thanks @jorangreef:
Yes, the process title is some weird characters that I didn't recognize. But with { name: 'Test' }
, it works.
from sudo-prompt.
Hi @junjunruan, sudo.exec()
is similar to child_process.exec()
in that you simply pass the arguments as part of the command string (see the Node.js docs). There is therefore no [args]
argument when calling sudo.exec()
.
If you need to pass parameters to your batch file, just pass "test.bat arg1 arg2 ..." as your command string. You then need to know how to access arguments from within a Windows batch file (see StackOverflow).
from sudo-prompt.
Thanks @jorangreef. It works.
I have a few questions. Is it the right place to ask questions or is there other ways to contact you?
My questions are:
- From your documentation, I see this message: Passing options.name or options.icns is currently not supported by sudo-prompt on Windows. Then what the syntax should be for windows?
I tried delete options json, and remove "options" from sudo.exec(), it doesn't work.
The only way it works for me now is leave options json and parameter there. - I have several commands in my .cmd batch file need admin right, is there any ways to remember user's choice ("Yes") in the first time so that the dialog doesn't need to prompt every time?
(maybe save the windows username and password when the first time a user clicks yes?) - What if the user click "NO" when the dialog popup (user did not grant permission), is there any ways to keep popup the dialog until user choose YES?
from sudo-prompt.
Sure, you're welcome to ask here and it might be helpful to others. Regarding your questions:
- Just pass
{}
as options on Windows. - No, we delegate the privilege elevation to Windows itself. Windows shows the dialog prompt and we never receive the username and password (this would also not be safe). The best thing is to create a batch script which does everything that requires admin rights, and then execute this batch script using sudo-prompt's
exec()
. That way the user will only receive a single password prompt each time you run the batch script. - Sure, you could just call
exec()
again but this would be annoying to the user. Perhaps you could explain to the user in advance why you need admin privileges, so that they are more likely to accept?
from sudo-prompt.
Thanks for your quick response @jorangreef.
Here is what I tried based on your suggestion:
1.I got an error: process.title cannot be used as a valid name
after I changed to the following code:
process.title = "electron";
sudo.exec('echo hello', {}, function(error, stdout, stderr) {});
I checked the default value of process.title, the result is some Unrecognizable code.
2.I think what you mean if put all the commands need admin right in a batch file, then have one sudo.exec() to run at once.
But in my case, I have several sudo.exec() in my code by passing different parameters to run the batch file.
sudo.exec('test.cmd param1', options, function(error, stdout, stderr) {});
sudo.exec('test.cmd param2', options, function(error, stdout, stderr) {});
My batch file is similar to:
if(param1) run command1
if(param2) run command2
from sudo-prompt.
Sure,
- It may be that your process title was not in English?
sudo-prompt
requiresoptions.name
to be alphanumeric, and uses the process title ifoptions.name
is not provided. To solve this, just try using{ name: 'Test' }
as youroptions
object instead of{}
. - Then you would need two prompts, unless you can restructure things.
from sudo-prompt.
Related Issues (20)
- 'Command failed' in Electron app HOT 1
- Not possible in Mac App Store, aka app-sandbox HOT 5
- macOS Catalina Operation not permitted HOT 1
- OS dialog prompt is not being prompted in Windows 10 HOT 1
- Operation not permitted in macOS with sudo-prompt
- Prompt shows but name and icon are not visible on macOS HOT 8
- "User did not grant permissions" if I click "Yes" too quickly on Windows? HOT 1
- `sudo-prompt` fails to detect `pkexec` or `kdesudo` in "strictly" confined snap
- Special characters handling on Linux
- Strange behaviour with Electron 9 on Win10 HOT 1
- in Eelectron app Rendering process, sudo run cp not work
- Hello, why option.name just support [a-z0-9 ] ?
- How to get elevated shell and run a command without sudo prefix HOT 1
- macOS: Application cannot be opened because the developer cannot be verified
- BigSur 11.1 issue: The authorization was denied since no user interaction was possible HOT 1
- Linux: option.env not used
- Unexpected behaviour with linux - electron.js HOT 1
- electron exe with root system privileges in linux, It's possible to do ?
- How to run multiple commands without requiring password every time HOT 6
- Any pkg similar to this, but without root/admin?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sudo-prompt.