Running Programs As Root In Non Root Shell (Powershell)
36
If the current console is not elevated and the operation you're trying to do requires elevated privileges then you can start powershell with the "Run as administrator" option
PS> Start-Process C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Verb runAs
Source: StackOverflow
Related videos on Youtube
Author by
The Klatu
Updated on September 18, 2022Comments
-
The Klatu over 1 year
I'm new to python and I need to log in to a website but I can only find articles and videos that talks about the POST method form login and I can't figure out how to login in a form that uses a GET method. This code I believe is for the POST method isn't it? The website I want to log in uses get method
import requests from bs4 import BeautifulSoup headers = { 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' } login_data = { 'name': '<username>', 'pass': '<password>', 'form_id': 'new_login_form', 'op': 'Login' } with requests.Session() as s: url = 'https://www.codechef.com/' r = s.get(url, headers=headers) soup = BeautifulSoup(r.content, 'html5lib') login_data['form_build_id'] = soup.find('input', attrs={'name': 'form_build_id'})['value'] r = s.post(url, data=login_data, headers=headers) print(r.content)
-
Seth Wilson almost 11 yearsUnfortunitely it said it could not find the find the file cmd.exe, even when I typed in the entire directory. This is truly strange to me.
-
Seth Wilson almost 11 yearsI got the error "Start-Process : The system could not find the environment option tat was entered." I assume that occurred because of my non-existent %WINDIR% environment variable.
-
nixda almost 11 yearsCorrect. In your case you have to specify the full path for "Powershell":
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
-
LawrenceC almost 11 yearstry
c:\windows\system32\runas.exe /user:Administrator c:\windows\system32\cmd.exe
-
Seth Wilson almost 11 yearsAlright I filled in the whole directory now but it still did not work. It did actually work though without the arguments (-Verb and runAs) you listed.
-
nixda over 10 yearsI corrected a stupid mistake. See my edit, it should work now.
-
The Klatu almost 4 yearsI'm sorry but I figured out the stupidity of my question 1 minute after I posted it. I used the code that I sent before changing it to fit my needs, now that I'm logged in tho I have to figure out how to stay logged in and go to the page I need to scrape. Do you have any suggestions?
-
Donatien almost 4 yearsSince you are scraping, your authentication is probably done through a cookie that the request session should keep and add to any further request. So I think it should work on it's own. You can check if you have a cookie after login by printing s.cookie.