Page 1 of 1

A bug in Scripting or a bug in me?

Posted: 13 Jun 2012 15:50
by aurumdigitus
Using Windows 7, 64 bit.

Object: To open directly the System Protection Tab of System Properties.

Using the Run box this works fine "systempropertiesprotection".

Using script of

Code: Select all

run "systempropertiesprotection";
produces instead the System Propteries Computer Name Tab.

May be missing something obvious but by no means intuitive what.

Re: A bug in Scripting or a bug in me?

Posted: 13 Jun 2012 16:00
by TheQwerty
I think it's related to XY being 32-bit.

Compare what you get when running it from the different bit-ness command prompts:
C:\Windows\SysWOW64\cmd.exe
C:\Windows\System32\cmd.exe

EDIT: Try this instead:

Code: Select all

::run '"C:\Windows\SysNative\cmd.exe" /C systempropertiesprotection',,,0;

Re: A bug in Scripting or a bug in me?

Posted: 13 Jun 2012 16:16
by aurumdigitus
Profound thank you yet again, TheQwerty! Works perfectly.

But such convoluted syntax. The sun would have gone nova before I ever came up with that. :roll:

Re: A bug in Scripting or a bug in me?

Posted: 13 Jun 2012 17:07
by TheQwerty
aurumdigitus wrote:But such convoluted syntax. The sun would have gone nova before I ever came up with that. :roll:
:lol: heh...

Since SysNative is a virtual directory that is only visible in 32-bit apps, presumably only when 32-bit apps are run on 64-bit Windows, and since the possibility exists that XY might eventually become 64-bit, that should probably be even more convoluted.

To future proof it and make it more forgiving I think this would work but this is NOT tested:

Code: Select all

"System Properties Protection"
	// Use existence of SysNative to detect 32-bit XY on 64-bit OS.
	$cmd = "%SystemRoot%\SysNative\cmd.exe";
	if (! exists($cmd)) {
		// Not sure if we should fallback to ComSpec or System32 first.
		$cmd = "%SystemRoot%\System32\cmd.exe"; // Could replace with XY-only: %WinSysDir%\cmd.exe
		if (! exists($cmd)) {
			$cmd = "%ComSpec%";
			End ! Exists($cmd), "I give up trying to locate cmd.exe - go away!";
		}
	}

	run """$cmd"" /C systempropertiesprotection",,, 0;
Fortunately, when XY's and the OS' architectures match there's probably no reason to run the command through cmd.exe so maybe even replace that with (again NOT tested):

Code: Select all

"System Properties Protection"
	// Use existence of SysNative to detect 32-bit XY on 64-bit OS.
	$cmd = "%SystemRoot%\SysNative\cmd.exe";
	if (exists($cmd)) {
		run """$cmd"" /C systempropertiesprotection",,, 0;
	} else {
		run 'systempropertiesprotection';
	}
EDIT: Of course even if this was thoroughly tested 100% coverage can't be achieved until there's a 64-bit version of XY. ;)

Re: A bug in Scripting or a bug in me?

Posted: 14 Jun 2012 12:37
by aurumdigitus
@TheQwerty - Your extended code has been filed away for future use should the need arise.

Thanks again for your time and trouble. You are an asset to the XY community. :appl: