Elevated command prompt vs. Run as administrator
I've been looking for an answer on this particular question. The situation is as follows:
I have a .cmd file that starts up a NodeJS script that creates/deletes/alters windows services of an application. This is done using the package node-windows and also requires some access to the file system to retrieve some parameters.
The content of the .cmd file is very simple:
@echo off echo <some_text>. node <relative_path_to_file>\utils-services.js start all pause
What I notice is the following:
- When run using a right-mouse click and selecting Run as Administrator this fails
- When run from an elevated command prompt this succeeds.
The question now is, what is the difference between the two that causes this behavior ? I'm really curious and could not find an adequate answer. Thank you in advance!
The difference from you to others is you are always asking Windows to guess what you want.
Just tell it. No relative paths, simple.
See also questions close to this topic
ENV vars are not set through npm start (run-script) (on Windows git-bash)
I have installed git-bash to be able to set env vars like that
<VAR>=<value> node ..., but now it's working only if I run node. If I do it through npm start (
"start": "ENV=development node server.js"), ENV would not be set. That's strange.
But if I do
ENV=development npm startor
ENV=development node server.js, it sets.
Where could the problem be?
P.S. I run bash through typing
bashin powershell (I tried to do bash selectable in visual code terminal, even though I added ../git/bin/ to the PATH I still don't see it).
Excel VBA - WinHttp request to an internal corporate server is now returning 504 error however XMLHTTP is still working fine
I was until recently successfully using WinHttp to make rest Excel VBA Rest api calls to one of our internal servers.
However something has recently changed (I assume on our internal network) and this has started to fail, throwing a 504 "Unknown Host" response. The strange thing is that calls using XMLHTTP to the same server are still working, as are calls using WinHttp to other external services. I have also tried on at least one other internal service but I am still getting the same results (WinHttp doesn't work but XMLHTTP does).
I don't think there is anything wrong with my code, here are some examples anyway. Any suggestions on what might be the cause?
Sub ApiCall() Dim web_Http As Object Set web_Http = CreateObject("WinHttp.WinHttpRequest.5.1") web_Http.Open "GET", Url, False web_Http.setRequestHeader "Authorization", "Basic " & encodedUserNamePsswrd web_Http.Send Debug.Print "Result: " & web_Http.Status & " - " & web_Http.responseText End Sub
Result: 504 - <HEAD><TITLE>Unknown Host</TITLE></HEAD> <BODY BGCOLOR="white" FGCOLOR="black"><H1>Unknown Host</H1><HR> <FONT FACE="Helvetica,Arial"><B> Description: Unable to locate the server named "<em>server</em>" --- the server does not have a DNS entry. Perhaps there is a misspelling in the server name, or the server no longer exists. Double-check the name and try again.</B></FONT> <HR> <!-- default "Unknown Host" response (504) --> </BODY>
Now if I do the exact same thing with XMLHTTP and it works just fine, with a nice 200 result:
Sub ApiCall() Dim web_Http As Object Set web_Http = CreateObject("MSXML2.XMLHTTP") web_Http.Open "GET", Url, False web_Http.setRequestHeader "Authorization", "Basic " & encodedUserNamePsswrd web_Http.Send Debug.Print "Result: " & web_Http.Status & " - " & web_Http.responseText End Sub
Windows 10 Pro as RDP Host with COMODO SSL Certificate. How?
I have exhausted my patience looking for how do add an SSL certificate to my Windows 10 Pro machine so that when I connect from another place, I don't get certificate errors.
So far, every guide I run into eventually turns out to be for Windows Server.
What I've tried:
I click on start menu then type
certlm.mscand hit Enter.
I place my purchased certificate in the Host Machine's
Personal > Certificatesfolder AND the
Remote Desktop > Certificate Servicefolder.
When I try to reconnect from another machine, I still get the certificate trust error.
Can anyone help?
Again, I am trying to accomplish this in a Windows 10 Pro machine, NOT Windows Server.
Batch File to pull out a number from an XML file
I have a batch file that downloads a XML file every few seconds. the data in the file looks like this
<?xml version='1.0' encoding='iso-8859-1'?> <TRAFFIC> <data storeId="OCF0001" color="green" occDate="2020-12-01 13:02:31" occLevelNow="121" occLevel-1="120" occLevel-2="121" occLevel-3="122" occLevel-4="123" occLevelMax="200" occLevelPct="60.5 %"/> <outputMessage text="Traffic Data generated successfully."/> </TRAFFIC>
I would like to build a RSS file with just the Value after the occLevelNow= (In this case 121 without the quotes)
I can do the batch file to print out the new file in the correct format. I am just having a problem getting just the 121 number. I have tried using the For /F and Findstr command but for some reason I can not get it to find the right value. any help would be awesome.
Batch script to logoff users remotely except the mentioned ones
The below batch script checks for the mentioned users among the listed remote servers and if the mentioned user names are found then it will log off the users from the listed servers remotely. This works fine as expected.
@ECHO off SETLOCAL SET "users=USER01 USER02" SET "servers=SERVER1 SERVER2 SERVER3 SERVER4" FOR %%s IN (%servers%) DO ( FOR /f "tokens=1,2" %%a IN ('"Quser /server:%%s"') DO ( FOR %%n IN (%users%) DO ( IF /I %%a==%%n rwinsta /server:%%s %%b ) ) )
I further managed to experiment and now with the below script I am now able to make sure one particular user (USER2) out of 3 users can be skipped from logging off. Rest of the users mentioned under user list will be logged off
@ECHO off SETLOCAL SET "users=USER1 USER2 USER3" SET "servers=SERVER1 SERVER2 SERVER3 SERVER4" FOR %%s IN (%servers%) DO ( FOR /f "tokens=1,2" %%a IN ('"Quser /server:%%s"') DO ( FOR %%n IN (%users%) DO ( IF /I %%a EQU %%n IF /I "%%n" NEQ "USER2" rwinsta /server:%%s %%b ) ) )
But how can I make sure one more user can be skipped? If I added another If condition with NEQ "USER3" it won't work as per the logic.
Is there any other way were we can log off all users except User1, user2 and user3 from mentioned servers?
Beginning to use NLP after a long hiatus
I last used Stanford NLP back in 2014. After a long diversion, I am back to using it again. I downloaded version 3.3.0, which I last used then and have been having trouble remembering all of the bits and pieces necessary to run it. Right now I am using a .bat file I pulled from archive, viz:
@echo off :: Runs the English PCFG parser on one or more files, printing trees only :: usage: lexparser fileToparse java -cp stanford-corenlp-3.3.0.jar;stanford-corenlp-3.3.0-models.jar;xom.jar;joda-time.jar;jollyday.jar edu.stanford.nlp.pipeline.StanfordCoreNLP -annotators tokenize,ssplit,pos,lemma,ner,parse,dcoref -filelist input.txt cmd /k
I am getting an
out of memoryfailure and have raised the memory in Java to
4096mwith no relief.
(1) Is Java 32 bit what I should be using or 64. Currently using version 8.
(2) Is there a reference on how to set up java .bats for NLP available? I've searched through the website with no joy so far.
I would really appreciate some advice.
How do I trim X amount of characters of ALL files in ALL subfolders of a directory?
I've seen related topics to this but not quite exactly this one.
I want to know how I can use Powershell (Or CMD) to search all subfolders of a drive and subfolders within those subfolders to trim all file names by X amount of characters.
For Example, in removable drive I:\FATMEGAFOLDER , there are many subfolders with many WAV files, some of which are incredibly long and don't suit my needs, but there are way way way too many folders to manually rename. It's been 2 days I've started renaming and trimming my files manually and it simply is too much to do manually, there's just way too many folders and way too many files.
This is why I need this script. How can I make it so Powershell will go to the deepest ends of each folder and trim each file by x amount?
Run multiple commands inside a new shell
I want to run a command in a new cmd window then close that window.
start "New Window" /D C:\Users tree. I then want that window to close.
start "New Window" /D C:\Users tree&exitdoesn't work because the exit is applied to the original window. I then tried
start "New Window" /D C:\Users "tree&exit"but that just errors.
Is there a way to group the end bit of the command so that it is executed in the new window?
NetUserChangePassword() can set a password to Administrator?
When you enable Administrator user to login, the password is empty by default. At least on Windows 10, if you want login in a remote computer (via RDP) with Administrator user, must set a password before.
NetUserChangePassword()will be successful to this? considering that usually remote computer have only 2 users (already including Administrator), then my application is executed on second user >>
- How to enable expire web content in IIS using powershell
UAC and Executing Jobs via a Windows Service
I have a custom service that executes other jobs. Need to get it to work with UAC.
To one of the applications, I was calling, I added the manifest with the line:
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
When trying to call this EXE from the service, I get an error: Failed: The requested operation requires elevation
Here's the code calling the EXE, it's very generic:
p.StartInfo.UserName = szUser p.StartInfo.Domain = szDomain p.StartInfo.Password = securePassword p.StartInfo.WorkingDirectory = sStartPath p.StartInfo.FileName = jobExecutable p.StartInfo.Arguments = jobArguments p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardInput = False p.Start() -- MORE CODE
So, what action do I need to take to allow a single program to "Run as Administrator" from a non-interactive service? Does the Windows service need it's own administrator manifest? Would that fix the problem, or is another code change required?
Create PSCredential from AzureAD User
I don't know why I can't figure this out, this can't be as hard as I'm making it. I'm trying to create a powershell script that will elevate itself using explicit credentials from AzureAD. I create a PSCredential object with:
$ss = ConvertTo-SecureString "p@ssw0rd" -AsPlainText -Force $cred = New-Object PSCredential -ArgumentList 'firstname.lastname@example.org', $ss Start-Process PowerShell -Credential $cred "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`"" exit;
When I execute this I get
Start-Process : This command cannot be run due to the error: The user name or password is incorrect.
I know the username and password are correct but I am guessing that it has to do with the fact that this is an AzureAD user? Do I have to format the AzureAD username differently? I've tried reformatting it every way I can think of. I've tried using
Get-AzureADUserto try to see if I could use some property of that to sign in but I'm coming up empty.
Is this even possible?
Runas admin working in cmd, but not in powershell
I'm trying to start a elevated powershell without user input, so I use
runas /user:myadmin Powershell.exe. Now this works fine in a normal cmd, however if I try to run the same exact command in a python subprocess, or even a just a powershell script I get
1326: The user name or password is incorrect.. I've got no clue why it doesn't work outside of cmd, and I've been trying to figure it out all day, if anyone could help, it'd be well appreciated.