Putting the screen working area into environment variables

BTW, using my Local Group Policy Editor, under “Computer Configuration”, “Windows Settings”, “Sotfware Restriction Policies” I see that no software restriction policies have been defined.

Under “User Configuration”, “Window Settings”, “Security Settings”, “Public Key Policies” it lists the following two items:

Certificate Services Client - Certifcate Enrollment Policy
Certificate Services Client - Auto-Enrollment

I assume this is all default stuff, since I haven’t run the group policy editor before. And BTW this is not an enterprise system. It is set up with a single user (which is also an admin).
~Paul

Did you try “PowerShell -ExecutionPolicy Bypass .\workingArea.ps1” from your admin shell??

I just tried that. Opening a regular command window in administrator mode, I tried:

e:\Octave>Powershell -ExecutionPolicy Unrestricted ./workingArea.ps1

The script executed perfectly. It also worked if I used Bypass instead of Unrestricted.
If I removed the execution policy switch completely, then I got the usual message about running scripts being disabled.

So why can’t I run this script from the powershell window itself?

Well, not sure, but I can say that I can run either way, PowerShell or Command shell. This might be nit picking, but did you try .\workingArea.ps1 instead of ./workingArea.ps1 ?? Maybe a PowerShell is Strict.

No tonyd, it gave the same error using \ or /.

At any rate, I got my octave script working by writing both a .ps1 and a .bat file. The ps1 file actually saves the working area information in a file and the .bat file merely runs the .ps1 script. I don’t understand why I needed the .bat file at all, but at this point I’m not going to argue with success. The script returns the correct results using Octave as well as very new and very old versions of Matlab.
I couldn’t have gotten this working without all your help, so many thanks.
The final .m script for any of you who are interested follows:

function p = workingArea()
% returns [x y width height] of the primary display useable are not including the taskbar
% where: x is the distance in pixels from the left edge
%        y is the distance in pixels from the bottom edge
% examples:
% figure('OuterPosition',workingArea);      % creates figure filling the entire useable screen area
% w = workingArea;
% v = w + [8 8 -16 -16];
% figure('OuterPosition',v);                % similar, except gives you an 8 pixel margin on all sides
% v = [w(1) w(2) 380 250];
% figure('OuterPosition',v);                % creates a 380 by 250 figure in the lower left corner of the working area
% v = [w(1)+w(3)-380 w(2) 380 250];
% figure('OuterPosition',v);                % creates a 380 by 250 figure in the lower right corner of the working area
% v = [w(1) w(2)+w(4)-250 380 250];
% figure('OuterPosition',v);                % creates a 380 by 250 figure in the upper left corner of the working area
% v = [w(1)+w(3)-380 w(2)+w(4)-250 380 250];
% figure('OuterPosition',v);                % creates a 380 by 250 figure in the upper right corner of the working area
% v = [w(1)+w(3)-300 w(2) 300 w(4)];
% figure('OuterPosition',v);                % creates the tallest 300 pixel wide figure as far to the right as possible
% v = [w(1) w(2)+w(4)-200 w(3) 200];
% figure('OuterPosition',v);                % creates the widest 200 pixel high figure as far to the top as possible
%
  f3 = which(mfilename);  % path and file name of this function
  f3(end)='';             % remove .m extension
  f1 = [f3 'ps1'];        % name of powershell script
  f2 = [f3 'txt'];        % name of powershell script results file
  f3 = [f3 'bat'];        % name of batch file to run the powershell script
  if ~exist(f1)           % create powershell script file if it doesn't already exist
    f = fopen(f1,'w');
    fprintf(f,'Add-Type -AssemblyName System.Windows.Forms\n');
    fprintf(f,'$Scr = [System.Windows.Forms.Screen]::AllScreens\n');
    fprintf(f,'$Di = $Scr | Where-Object -FilterScript {$_.DeviceName -match ''DISPLAY1''}\n');
    fprintf(f,'$Di.WorkingArea.X, $Di.WorkingArea.Y,\n');
    fprintf(f,'$Di.WorkingArea.Width, $Di.WorkingArea.Height, $Di.Bounds.Height |\n');
    fprintf(f,'Out-File -FilePath %s -Encoding ASCII\n',f2);
    fclose(f);  f = fopen(f3,'w');  % also create the batch file
    fprintf(f,'Powershell -ExecutionPolicy Bypass %s\n',f1);  fclose(f);
  end;
  dos(f3);                              % run the batch file
  if exist('textscan')                  % read script results using textscan
    f = fopen(f2);
    p = textscan(f,'%d');
    p = p{1};  fclose(f);
  else p = textread(f2,'%n');           % use textread instead for older matlab versions
  end;
  p(2) = p(5) - p(2) - p(4);            % convert top edge coordinates to bottom edge
  p = p(1:4)';                          % return first four elements as row vector

Never argue with Success :slight_smile: Glad you got it figured.