Linux HowTo: %PROMPT% variable resolved differently if set directly in CMD or by Windows variables tool

Original Source Link

When trying to customize my command prompt I faced a strange behaviour:

from the CMD the line

SET set prompt=$D $T$H$H$H$_%USERNAME%@%COMPUTERNAME%$_$P$G

works as expected:

28/05/2020 12:02:15
[email protected]
C:UsersDDS>

But if I set the same variable EDIT: (in “variable for user DDS”) with the very same values from the windows utility to set variables I got:

28/05/2020 12:04:18
[email protected]
C:UsersDDS>

NOTE: the utility itself is showing the value correctly DDS when editing the variables, just the command prompt resolves %USERNAME% to SYSTEM

When you execute this from the system app, it is run under the SYSTEM user.

Keep in mind that the variables are not updated with every prompt. This means that if you were to change your username, your prompt does not. It becomes a static text. Given that you use prompt variables for the date, they get updated, but the computername and username are not.

I don’t think this is going to be a massive problem, but you can do 2 things to resolve this. Either not use %USERNAME% but just write out your username (it doesn’t matter anyway) or use the command prompt to set the prompt correctly, then push that to the system using:

setx PROMPT %PROMPT%

To test this, try using %CD% in your prompt, then change directory. Notice how your prompt still shows the old directory.

Tagged : / /

Making Game: %PROMPT% variable resolved differently if set directly in CMD or by Windows variables tool

Original Source Link

When trying to customize my command prompt I faced a strange behaviour:

from the CMD the line

SET set prompt=$D $T$H$H$H$_%USERNAME%@%COMPUTERNAME%$_$P$G

works as expected:

28/05/2020 12:02:15
[email protected]
C:UsersDDS>

But if I set the same variable EDIT: (in “variable for user DDS”) with the very same values from the windows utility to set variables I got:

28/05/2020 12:04:18
[email protected]
C:UsersDDS>

NOTE: the utility itself is showing the value correctly DDS when editing the variables, just the command prompt resolves %USERNAME% to SYSTEM

When you execute this from the system app, it is run under the SYSTEM user.

Keep in mind that the variables are not updated with every prompt. This means that if you were to change your username, your prompt does not. It becomes a static text. Given that you use prompt variables for the date, they get updated, but the computername and username are not.

I don’t think this is going to be a massive problem, but you can do 2 things to resolve this. Either not use %USERNAME% but just write out your username (it doesn’t matter anyway) or use the command prompt to set the prompt correctly, then push that to the system using:

setx PROMPT %PROMPT%

To test this, try using %CD% in your prompt, then change directory. Notice how your prompt still shows the old directory.

Tagged : / /

Linux HowTo: Set FFmpeg Process Priority with 2 Pass

Original Source Link

I’m using FFmpeg with Command Prompt.

I’m setting the process priority with start /low /b.


When pass 1 finishes, it launches FFmpeg again for pass 2 using &&.

start /low /b ffmpeg -i "C:video.mpg" -c:v libx264 -b:v 1500K -pass 1 "C:video.mp4" &&
start /low /b ffmpeg -i "C:video.mpg" -c:v libx264 -b:v 1500K -pass 2 "C:video.mp4"

Problem

Using start /low /b with pass 2 causes the error:

Failed to initialize encoder: Invalid parameter
Additional information: rc_twopass_stats_in.buf not set.

and pass 2 never starts.

Tagged : / /

Making Game: What group does the user running a command with elevated permissions belong to?

Original Source Link

I am not particularly familiar with Windows permissions, but I had assumed that elevated permissions were equivalent to sudo. However, I came across this “unexpected” behavior when running a simple python program via cmd.exe and powershell, which leads me to believe that it’s not so clear-cut:

When the target directory has 755 permissions (the default), I cannot write to the directory if I’m running cmd.exe/powershell with elevated permissions. I can write to the directory if I’m not running elevated. If I change the directory permissions to 766, I can write to it with either elevated/regular permissions.

Using windows cli (cmd.exe or powershell):

echo "asdf" > testdirtestfile.txt

And a minimal example in python:

import os 

def main():
    fname = os.path.join(os.path.dirname(os.path.realpath(__file__)), "testdir", "testfile.txt")
    f = open(fname, "w")
    f.write("asdf")
    f.close()

if __name__ == "__main__":
    main()

So, what group does the elevated user belong to? And why does the elevated user not have permissions to directories that they created as a “non-elevated” user?

Tagged : / / / /

Making Game: Set FFmpeg Process Priority with 2 Pass

Original Source Link

I’m using FFmpeg with Command Prompt.

I’m setting the process priority with start /low /b.


When pass 1 finishes, it launches FFmpeg again for pass 2 using &&.

start /low /b ffmpeg -i "C:video.mpg" -c:v libx264 -b:v 1500K -pass 1 "C:video.mp4" &&
start /low /b ffmpeg -i "C:video.mpg" -c:v libx264 -b:v 1500K -pass 2 "C:video.mp4"

Problem

Using start /low /b with pass 2 causes the error:

Failed to initialize encoder: Invalid parameter
Additional information: rc_twopass_stats_in.buf not set.

and pass 2 never starts.

Tagged : / /

Linux HowTo: Emulate a keyboard button via the Command Line

Original Source Link

My keyboard doesn’t have a Num Lock key, and none of the registry edits work for some reason.

Can I use the Command Prompt or PowerShell on Windows 10 to “press” a key? I’m looking for something like press pgup to press the Page Up Key in the Command Prompt or PowerShell, but for Num Lock.

How do I toggle numlock status using PowerShell.

Use the following script:

$wsh = New-Object -ComObject WScript.Shell
$wsh.SendKeys('{NUMLOCK}')

Source StackOverflow answer PowerShell: Toggle “Num Lock” on and off. by Andy Arismendi

As pointed out by ABashore in his comment this can be shortened as follows:

$wshell.SendKeys('{NUMLOCK}')

Here’s a powershell line that will toggle your NUMLOCK. I’ve tested this and it works on my Logitech K120 USB keyboard.

$wshell.SendKeys('{NUMLOCK}')

Here’s a list of the other SendKey codes.

If you need to send the keystroke to an interactive application, more code will be needed.

Batch

Without creating temporary files.
The ‘loop’ was shown only so that you could open a notebook for output. Remove it after.

    @echo off
        :loop
            ::------------begin main code------------
            set command=new ActiveXObject('WScript.Shell').SendKeys('WoW{ENTER}{ENTER}');
            for /f "delims=" %%i in ('mshta "javascript:%command%close(new ActiveXObject('Scripting.FileSystemObject'));"') do set
            ::-------------end main code-------------
            timeout /t 1 /nobreak >nul
        goto :loop

Tagged : / / / /

Making Game: Emulate a keyboard button via the Command Line

Original Source Link

My keyboard doesn’t have a Num Lock key, and none of the registry edits work for some reason.

Can I use the Command Prompt or PowerShell on Windows 10 to “press” a key? I’m looking for something like press pgup to press the Page Up Key in the Command Prompt or PowerShell, but for Num Lock.

How do I toggle numlock status using PowerShell.

Use the following script:

$wsh = New-Object -ComObject WScript.Shell
$wsh.SendKeys('{NUMLOCK}')

Source StackOverflow answer PowerShell: Toggle “Num Lock” on and off. by Andy Arismendi

As pointed out by ABashore in his comment this can be shortened as follows:

$wshell.SendKeys('{NUMLOCK}')

Here’s a powershell line that will toggle your NUMLOCK. I’ve tested this and it works on my Logitech K120 USB keyboard.

$wshell.SendKeys('{NUMLOCK}')

Here’s a list of the other SendKey codes.

If you need to send the keystroke to an interactive application, more code will be needed.

Batch

Without creating temporary files.
The ‘loop’ was shown only so that you could open a notebook for output. Remove it after.

    @echo off
        :loop
            ::------------begin main code------------
            set command=new ActiveXObject('WScript.Shell').SendKeys('WoW{ENTER}{ENTER}');
            for /f "delims=" %%i in ('mshta "javascript:%command%close(new ActiveXObject('Scripting.FileSystemObject'));"') do set
            ::-------------end main code-------------
            timeout /t 1 /nobreak >nul
        goto :loop

Tagged : / / / /

Linux HowTo: Internet Connection Sharing + Port Forwarding range

Original Source Link

I’m using Internet Connection Sharing from a Windows 10 computer in order to give a device internet connection and would like to use port forwarding from this connection as well but I need to add a large range of ports (20k+ ports).

Is there a way to add these ports via the command line? A way to add a range?

For anyone who’s struggling as much as I was. I’ve figured it out using JScript (C++ went way over my head)

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ics/adding-and-removing-port-mappings-jscript-

The documentation is slightly wrong as theres "&" instead of just “&” and some missing semicolons, but it got me to where I need to be.

Tagged : / / / /

Making Game: PowerCmd does not print out aws commands’ outputs

Original Source Link

aws commands works well with cmd.exe. But the outputs are not shown when I use it with Powercmd.
I’ve attached one example.
enter image description here

It seems that Powercmd is not throwing any error. I can enter credentials but it just does not print outputs. Above is one example. Even after I set up aws with configure command successfully, outputs are not printed with commands.(The problem is only when I use aws)

Tagged : / / /

Linux HowTo: OSPP.VBS cmd prompt

Original Source Link

I am running into a problem with running the following command in cmd to retrieve the last 5 digits of my Office key.

The command prompt is as follows:

cscript “C:Program Files (x86)Microsoft OfficeOffice15OSPP.VBS” /dstatus

Opening CMD, I changed the directory to the root of C: and ran the command, but I get the following error:

"Input Error: There is no file extension in "C:"C:program"."

I verified the file is there in the program files x86 folder, so I am not sure where I am going wrong. Any help would be appreciated.

Open cmd as administrator

type cd C:Program Files/Microsoft Office/Office16

hit enter

then you want to type ospp.vbs /dstatus

done

Tagged : / /