Check-in [40b1957fe8]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added IsWorkstationLocked and FinalPathNameByHandle, two command-line utilities. IsWorkstationLocked reports whether the workstation is locked, or waits for the given status. FinalPathNameByHandle shows the final pathname of the given path; i.e. after resolving all junctions and symbolic links.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:40b1957fe892c98066eaec8eb6b4cce0c440e667
User & Date: Martijn 2013-11-26 18:53:30
Context
2014-01-03
09:09
Pulled help text of IsWorkstationLocked to external file, to be included as resource and loaded from there. This also allows direct inclusion in the Fossil project website. check-in: d93ac4d237 user: Martijn tags: trunk
2013-11-26
18:53
Added IsWorkstationLocked and FinalPathNameByHandle, two command-line utilities. IsWorkstationLocked reports whether the workstation is locked, or waits for the given status. FinalPathNameByHandle shows the final pathname of the given path; i.e. after resolving all junctions and symbolic links. check-in: 40b1957fe8 user: Martijn tags: trunk
18:49
initial empty check-in check-in: 53649ff619 user: Martijn tags: trunk
Changes

Added src/FinalPathNameByHandle.dpr.









































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
{$WARN SYMBOL_PLATFORM OFF}

program FinalPathNameByHandle;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Windows;

(* ---- *)

function FinalPathName(const PathName: string; out IsReparsePoint: boolean): string;
var
  dwAttr, dwFlagsAndAttr: DWord;
  Handle: THandle;
  uLen: UINT;
begin
  dwAttr := GetFileAttributes(PChar(PathName));
  Win32Check(dwAttr <> INVALID_HANDLE_VALUE);

  IsReparsePoint := 0 <> (dwAttr and FILE_ATTRIBUTE_REPARSE_POINT);

  if dwAttr and FILE_ATTRIBUTE_DIRECTORY = 0 then
    dwFlagsAndAttr := FILE_ATTRIBUTE_NORMAL
  else
    dwFlagsAndAttr := FILE_ATTRIBUTE_DIRECTORY or FILE_FLAG_BACKUP_SEMANTICS;

  Handle := CreateFile(PChar(PathName), GENERIC_READ, FILE_SHARE_READ,
                        nil, OPEN_EXISTING, dwFlagsAndAttr, 0);
  if (Handle = INVALID_HANDLE_VALUE) and (GetLastError = 5) then  // Access denied
    Handle := CreateFile(PChar(PathName), 0, FILE_SHARE_READ,
                          nil, OPEN_EXISTING, dwFlagsAndAttr, 0);
  Win32Check(Handle <> INVALID_HANDLE_VALUE);
  try
    SetLength(Result, MAX_PATH);
    uLen := GetFinalPathNameByHandle(Handle, PChar(Result),
                                      MAX_PATH, FILE_NAME_NORMALIZED);
    Win32Check(uLen > 0);
    SetLength(Result, uLen);
  finally
    CloseHandle(Handle);
  end;
end {FinalPathName};

var
  bReparsePoint: boolean;
  sLink, sTarget : String;
  uResult : UInt = 1;
begin { FinalPathNameByHandle }
//  WriteLn;

  if (ParamCount <> 1) then
  begin
    WriteLn(ChangeFileExt(ExtractFileName(ParamStr(0)), '') + ' [file or directory name]');
    Halt ($FF);
  end; { if }

  sLink := ParamStr (1);

  try
    sTarget := FinalPathName(sLink, bReparsePoint);
    uResult := 0;

//    if bReparsePoint then
//      WriteLn (Format ('"%s" is a Reparse Point', [sLink]))
//    else WriteLn (Format ('"%s" is not a Reparse Point', [sLink]));

    WriteLn(Format('"%s"', [sTarget]));

  except
    on E:Exception do
      WriteLn(Format('Exception %s: %s', [E.ClassName, E.Message]));
  end; { try / except }

  if (DebugHook > 0) then begin
    WriteLn;
    Write('Press [Enter] to continue ');
    ReadLn;
  end; { if }

  Halt (uResult);
end.

Added src/FinalPathNameByHandle.dproj.





























































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
	<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
		<PropertyGroup>
			<ProjectGuid>{9F0A95C0-593B-493C-8F9E-B7E65114296F}</ProjectGuid>
			<MainSource>FinalPathNameByHandle.dpr</MainSource>
			<Base>True</Base>
			<Config Condition="'$(Config)'==''">Release</Config>
			<TargetedPlatforms>1</TargetedPlatforms>
			<AppType>Console</AppType>
			<FrameworkType>None</FrameworkType>
			<ProjectVersion>13.4</ProjectVersion>
			<Platform Condition="'$(Platform)'==''">Win32</Platform>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
			<Base_Win32>true</Base_Win32>
			<CfgParent>Base</CfgParent>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
			<Cfg_1>true</Cfg_1>
			<CfgParent>Base</CfgParent>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
			<Cfg_2>true</Cfg_2>
			<CfgParent>Base</CfgParent>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
			<Cfg_2_Win32>true</Cfg_2_Win32>
			<CfgParent>Cfg_2</CfgParent>
			<Cfg_2>true</Cfg_2>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Base)'!=''">
			<PostBuildEventCancelOnError>false</PostBuildEventCancelOnError>
			<DCC_DcuOutput>..\out\DCU\$(PLATFORM)\$(CONFIG)</DCC_DcuOutput>
			<DCC_ExeOutput>..\out\$(PLATFORM)\$(CONFIG)</DCC_ExeOutput>
			<Manifest_File>None</Manifest_File>
			<PostBuildEvent><![CDATA[C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf "$(OUTPUTPATH)"
$(PostBuildEvent)]]></PostBuildEvent>
			<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
			<VerInfo_Locale>1043</VerInfo_Locale>
			<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace)</DCC_Namespace>
			<DCC_ImageBase>00400000</DCC_ImageBase>
			<DCC_E>false</DCC_E>
			<DCC_N>false</DCC_N>
			<DCC_S>false</DCC_S>
			<DCC_F>false</DCC_F>
			<DCC_K>false</DCC_K>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Base_Win32)'!=''">
			<DCC_Namespace>System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
			<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
			<VerInfo_Locale>1033</VerInfo_Locale>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_1)'!=''">
			<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
			<DCC_DebugInformation>false</DCC_DebugInformation>
			<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
			<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_2)'!=''">
			<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
			<DCC_Optimize>false</DCC_Optimize>
			<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
			<Manifest_File>None</Manifest_File>
			<VerInfo_Locale>1033</VerInfo_Locale>
		</PropertyGroup>
		<ItemGroup>
			<DelphiCompile Include="$(MainSource)">
				<MainSource>MainSource</MainSource>
			</DelphiCompile>
			<BuildConfiguration Include="Debug">
				<Key>Cfg_2</Key>
				<CfgParent>Base</CfgParent>
			</BuildConfiguration>
			<BuildConfiguration Include="Base">
				<Key>Base</Key>
			</BuildConfiguration>
			<BuildConfiguration Include="Release">
				<Key>Cfg_1</Key>
				<CfgParent>Base</CfgParent>
			</BuildConfiguration>
		</ItemGroup>
		<ProjectExtensions>
			<Borland.Personality>Delphi.Personality.12</Borland.Personality>
			<Borland.ProjectType/>
			<BorlandProject>
				<Delphi.Personality>
					<Source>
						<Source Name="MainSource">FinalPathNameByHandle.dpr</Source>
					</Source>
					<VersionInfo>
						<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
						<VersionInfo Name="AutoIncBuild">False</VersionInfo>
						<VersionInfo Name="MajorVer">1</VersionInfo>
						<VersionInfo Name="MinorVer">0</VersionInfo>
						<VersionInfo Name="Release">0</VersionInfo>
						<VersionInfo Name="Build">0</VersionInfo>
						<VersionInfo Name="Debug">False</VersionInfo>
						<VersionInfo Name="PreRelease">False</VersionInfo>
						<VersionInfo Name="Special">False</VersionInfo>
						<VersionInfo Name="Private">False</VersionInfo>
						<VersionInfo Name="DLL">False</VersionInfo>
						<VersionInfo Name="Locale">1043</VersionInfo>
						<VersionInfo Name="CodePage">1252</VersionInfo>
					</VersionInfo>
					<VersionInfoKeys>
						<VersionInfoKeys Name="CompanyName"/>
						<VersionInfoKeys Name="FileDescription"/>
						<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
						<VersionInfoKeys Name="InternalName"/>
						<VersionInfoKeys Name="LegalCopyright"/>
						<VersionInfoKeys Name="LegalTrademarks"/>
						<VersionInfoKeys Name="OriginalFilename"/>
						<VersionInfoKeys Name="ProductName"/>
						<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
						<VersionInfoKeys Name="Comments"/>
					</VersionInfoKeys>
					<Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\dcloffice2k160.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\dclofficexp160.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\bcboffice2k160.bpl">Embarcadero C++Builder Office 2000 Servers Package</Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\bcbofficexp160.bpl">Embarcadero C++Builder Office XP Servers Package</Excluded_Packages>
					</Excluded_Packages>
				</Delphi.Personality>
				<Platforms>
					<Platform value="Win64">False</Platform>
					<Platform value="OSX32">False</Platform>
					<Platform value="Win32">True</Platform>
				</Platforms>
			</BorlandProject>
			<ProjectFileVersion>12</ProjectFileVersion>
		</ProjectExtensions>
		<Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
		<Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
		<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win64'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='OSX32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win64'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='OSX32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
	</Project>

Added src/FinalPathNameByHandle.res.

cannot compute difference between binary files

Added src/IsWorkstationLocked.dpr.















































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
program IsWorkstationLocked;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  Winapi.Windows,
  DateUtils;

{ ------------------------------------------------------------------------------------------------ }
function fnIsWorkstationLocked: Boolean;
var
  hDesktop: HDESK;
begin
  Result := False;
  hDesktop := OpenDesktop('default', 0, False, DESKTOP_SWITCHDESKTOP);
  if hDesktop <> 0 then
  try
    Result := not SwitchDesktop(hDesktop);
  finally
    CloseDesktop(hDesktop);
  end;
end {IsWorkstationLocked};

{ ------------------------------------------------------------------------------------------------ }
procedure ShowHelp;
begin
  WriteLn(ChangeFileExt(ParamStr(0), ''), ' [/w:l[ock]] [/w:u[nlock]] [/w:t[oggle]] [/w:99999] [/w:HH:MM]');
  WriteLn('Reports whether the workstation is locked, or waits for the given status.');
  WriteLn;
  WriteLn('/w:lock        Waits until the workstation is locked, then returns.');
  WriteLn('/w:unlock      Waits until the workstation is unlocked, then returns.');
  WriteLn('/w:toggle      Waits until the workstation changes state, then returns.');
  WriteLn('               (i.e. if it''s locked, waits until unlock, otherwise until lock).');
  WriteLn;
  WriteLn('/w:99999       Times out after the given number of seconds, no matter what.');
  WriteLn('/w:HH:MM       Times out after the given (date and) time, no matter what.');
  WriteLn;
  WriteLn('Batch files can use this command''s return value to determine the status of the workstation.');
  WriteLn('ERRORLEVEL 0 means the workstation is not locked.');
  WriteLn('ERRORLEVEL 1 means the workstation is locked.');
  WriteLn('ERRORLEVEL 2 means no attempt was made to check the status of the workstation (e.g. this help was displayed).');
  WriteLn('ERRORLEVEL 3 or higher means an error has occurred.');
end {ShowHelp};

////////////////////////////////////////////////////////////////////////////////////////////////////
type
  TWaitEvent = (wfStatus, wfTimeout);
  TWaitEvents = set of TWaitEvent;
var
  i: Integer;
  Wait: TWaitEvents;
  bStatusLocked: Boolean;
  dtTimeout: TDateTime;
  iArg: Int64;
  sArg: string;
begin
  try
    Wait := [];
    bStatusLocked := False;
    for i := 1 to ParamCount do begin
      if (ParamStr(i) = '/?') or SameText(ParamStr(i), '/h') or SameText(ParamStr(i), '-h') or SameText(ParamStr(i), '--help') then begin
        ShowHelp;
        Halt(2);
      end else if SameText(Copy(ParamStr(i), 1, 4), '/w:l') then begin
        Include(Wait, wfStatus);
        bStatusLocked := True;
      end else if SameText(Copy(ParamStr(i), 1, 4), '/w:u') then begin
        Include(Wait, wfStatus);
        bStatusLocked := False;
      end else if SameText(Copy(ParamStr(i), 1, 4), '/w:t') then begin
        Include(Wait, wfStatus);
        bStatusLocked := not fnIsWorkstationLocked;
      end else if SameText(Copy(ParamStr(i), 1, 3), '/w:') then begin
        sArg := Copy(ParamStr(i), 4);
        if TryStrToInt64(sArg, iArg) and (iArg > 0) then begin
          Include(Wait, wfTimeout);
          dtTimeout := IncSecond(Now, iArg);
        end else if TryStrToTime(sArg, dtTimeout) then begin
          dtTimeout := Date + TimeOf(dtTimeout);
          if dtTimeout < Now then
            dtTimeout := dtTimeout + 1;
          Include(Wait, wfTimeout);
        end else if TryStrToDate(sArg, dtTimeout) then begin
          if dtTimeout < Now then
            Writeln(ErrOutput, DateTimeToStr(dtTimeout), ' lies in the past!')
          else
            Include(Wait, wfTimeout);
        end else if TryStrToDateTime(sArg, dtTimeout) then begin
          if dtTimeout < Now then
            Writeln(ErrOutput, DateTimeToStr(dtTimeout), ' lies in the past!')
          else
            Include(Wait, wfTimeout);
        end else begin
          Writeln(ErrOutput, 'I don''t know what to make of "', sArg, '"!');
        end;
      end;
    end;

    if fnIsWorkstationLocked then begin
      Writeln('Workstation is locked.');
    end else begin
      Writeln('Workstation is unlocked.');
    end;

    if Wait <> [] then begin
      Write('Waiting ');
      if (wfStatus in Wait) then begin
        Write('for workstation to be ');
        if bStatusLocked then Write('locked') else Write('unlocked');
      end;
      if Wait = [wfStatus, wfTimeout] then
        Write(', or ');
      if (wfTimeout in Wait) then begin
        Write('until ');
        if DateOf(dtTimeout) = Date then
          Write(TimeToStr(dtTimeout))
        else
          Write(DateTimeToStr(dtTimeout));
      end;
      WriteLn('.');
      repeat
        Sleep(1000);
        if (wfStatus in Wait) and (fnIsWorkstationLocked = bStatusLocked) then
          Wait := []
        else if (wfTimeout in Wait) and (Now > dtTimeout) then
          Wait := []
        ;
      until Wait = [];
      Write(DateTimeToStr(Now), ' - ');
      if fnIsWorkstationLocked then begin
        Writeln('Workstation is locked.');
      end else begin
        Writeln('Workstation is unlocked.');
      end;
    end;

    if fnIsWorkstationLocked then begin
      Halt(1);
    end else begin
      Halt(0);
    end;
  except
    on E: Exception do begin
      Writeln(ErrOutput, E.ClassName, ': ', E.Message);
      Halt(3);
    end;
  end;
end.

Added src/IsWorkstationLocked.dproj.

































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
	<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
		<PropertyGroup>
			<ProjectGuid>{CDA89E37-52DD-4AF7-B304-30B3CA2B5DAB}</ProjectGuid>
			<MainSource>IsWorkstationLocked.dpr</MainSource>
			<Base>True</Base>
			<Config Condition="'$(Config)'==''">Release</Config>
			<TargetedPlatforms>3</TargetedPlatforms>
			<AppType>Console</AppType>
			<FrameworkType>None</FrameworkType>
			<ProjectVersion>13.4</ProjectVersion>
			<Platform Condition="'$(Platform)'==''">Win32</Platform>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
			<Base_Win64>true</Base_Win64>
			<CfgParent>Base</CfgParent>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
			<Base_Win32>true</Base_Win32>
			<CfgParent>Base</CfgParent>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_1)'!=''">
			<Cfg_1>true</Cfg_1>
			<CfgParent>Base</CfgParent>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win32)'!=''">
			<Cfg_1_Win32>true</Cfg_1_Win32>
			<CfgParent>Cfg_1</CfgParent>
			<Cfg_1>true</Cfg_1>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_2)'!=''">
			<Cfg_2>true</Cfg_2>
			<CfgParent>Base</CfgParent>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_2)'=='true') or '$(Cfg_2_Win32)'!=''">
			<Cfg_2_Win32>true</Cfg_2_Win32>
			<CfgParent>Cfg_2</CfgParent>
			<Cfg_2>true</Cfg_2>
			<Base>true</Base>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Base)'!=''">
			<Manifest_File>None</Manifest_File>
			<PostBuildEventCancelOnError>false</PostBuildEventCancelOnError>
			<VerInfo_Locale>1043</VerInfo_Locale>
			<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
			<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
			<DCC_ExeOutput>..\out\$(PLATFORM)\$(CONFIG)</DCC_ExeOutput>
			<DCC_ImageBase>00400000</DCC_ImageBase>
			<DCC_N>false</DCC_N>
			<DCC_S>false</DCC_S>
			<PostBuildEvent><![CDATA[C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf "$(OUTPUTPATH)"
$(PostBuildEvent)]]></PostBuildEvent>
			<DCC_K>false</DCC_K>
			<DCC_DcuOutput>..\out\dcu\$(PLATFORM)\$(CONFIG)</DCC_DcuOutput>
			<DCC_E>false</DCC_E>
			<DCC_F>false</DCC_F>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Base_Win64)'!=''">
			<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
			<VerInfo_Locale>1033</VerInfo_Locale>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Base_Win32)'!=''">
			<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
			<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
			<VerInfo_Locale>1033</VerInfo_Locale>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_1)'!=''">
			<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
			<DCC_DebugInformation>false</DCC_DebugInformation>
			<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
			<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
			<VerInfo_Locale>1033</VerInfo_Locale>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_2)'!=''">
			<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
			<DCC_Optimize>false</DCC_Optimize>
			<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
			<Manifest_File>None</Manifest_File>
			<VerInfo_Locale>1033</VerInfo_Locale>
		</PropertyGroup>
		<ItemGroup>
			<DelphiCompile Include="$(MainSource)">
				<MainSource>MainSource</MainSource>
			</DelphiCompile>
			<BuildConfiguration Include="Debug">
				<Key>Cfg_2</Key>
				<CfgParent>Base</CfgParent>
			</BuildConfiguration>
			<BuildConfiguration Include="Base">
				<Key>Base</Key>
			</BuildConfiguration>
			<BuildConfiguration Include="Release">
				<Key>Cfg_1</Key>
				<CfgParent>Base</CfgParent>
			</BuildConfiguration>
		</ItemGroup>
		<ProjectExtensions>
			<Borland.Personality>Delphi.Personality.12</Borland.Personality>
			<Borland.ProjectType/>
			<BorlandProject>
				<Delphi.Personality>
					<Source>
						<Source Name="MainSource">IsWorkstationLocked.dpr</Source>
					</Source>
					<VersionInfo>
						<VersionInfo Name="IncludeVerInfo">False</VersionInfo>
						<VersionInfo Name="AutoIncBuild">False</VersionInfo>
						<VersionInfo Name="MajorVer">1</VersionInfo>
						<VersionInfo Name="MinorVer">0</VersionInfo>
						<VersionInfo Name="Release">0</VersionInfo>
						<VersionInfo Name="Build">0</VersionInfo>
						<VersionInfo Name="Debug">False</VersionInfo>
						<VersionInfo Name="PreRelease">False</VersionInfo>
						<VersionInfo Name="Special">False</VersionInfo>
						<VersionInfo Name="Private">False</VersionInfo>
						<VersionInfo Name="DLL">False</VersionInfo>
						<VersionInfo Name="Locale">1043</VersionInfo>
						<VersionInfo Name="CodePage">1252</VersionInfo>
					</VersionInfo>
					<VersionInfoKeys>
						<VersionInfoKeys Name="CompanyName"/>
						<VersionInfoKeys Name="FileDescription"/>
						<VersionInfoKeys Name="FileVersion">1.0.0.0</VersionInfoKeys>
						<VersionInfoKeys Name="InternalName"/>
						<VersionInfoKeys Name="LegalCopyright"/>
						<VersionInfoKeys Name="LegalTrademarks"/>
						<VersionInfoKeys Name="OriginalFilename"/>
						<VersionInfoKeys Name="ProductName"/>
						<VersionInfoKeys Name="ProductVersion">1.0.0.0</VersionInfoKeys>
						<VersionInfoKeys Name="Comments"/>
					</VersionInfoKeys>
					<Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\dcloffice2k160.bpl">Microsoft Office 2000 Sample Automation Server Wrapper Components</Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\dclofficexp160.bpl">Microsoft Office XP Sample Automation Server Wrapper Components</Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\bcboffice2k160.bpl">Embarcadero C++Builder Office 2000 Servers Package</Excluded_Packages>
						<Excluded_Packages Name="$(BDSBIN)\bcbofficexp160.bpl">Embarcadero C++Builder Office XP Servers Package</Excluded_Packages>
					</Excluded_Packages>
				</Delphi.Personality>
				<Platforms>
					<Platform value="Win64">True</Platform>
					<Platform value="OSX32">False</Platform>
					<Platform value="Win32">True</Platform>
				</Platforms>
			</BorlandProject>
			<ProjectFileVersion>12</ProjectFileVersion>
		</ProjectExtensions>
		<Import Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')" Project="$(BDS)\Bin\CodeGear.Delphi.Targets"/>
		<Import Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')" Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj"/>
		<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win64'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='OSX32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Release' And '$(Platform)'=='Win32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win64'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='OSX32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
		<PropertyGroup Condition="'$(Config)'=='Debug' And '$(Platform)'=='Win32'">
			<PreBuildEvent/>
			<PreBuildEventIgnoreExitCode>False</PreBuildEventIgnoreExitCode>
			<PreLinkEvent/>
			<PreLinkEventIgnoreExitCode>False</PreLinkEventIgnoreExitCode>
			<PostBuildEvent>C:\MC\Run\Tools\Compression\UPX\upx.exe -9 -qf &quot;$(OUTPUTPATH)&quot;</PostBuildEvent>
			<PostBuildEventIgnoreExitCode>True</PostBuildEventIgnoreExitCode>
		</PropertyGroup>
	</Project>

Added src/IsWorkstationLocked.res.

cannot compute difference between binary files

Added src/McTools.groupproj.

































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
	<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
		<PropertyGroup>
			<ProjectGuid>{E524DCBB-5D61-4724-94C8-4232A02D3276}</ProjectGuid>
		</PropertyGroup>
		<ItemGroup>
			<Projects Include="IsWorkstationLocked.dproj">
				<Dependencies/>
			</Projects>
			<Projects Include="FinalPathNameByHandle.dproj">
				<Dependencies/>
			</Projects>
		</ItemGroup>
		<ProjectExtensions>
			<Borland.Personality>Default.Personality.12</Borland.Personality>
			<Borland.ProjectType/>
			<BorlandProject>
				<Default.Personality/>
			</BorlandProject>
		</ProjectExtensions>
		<Target Name="IsWorkstationLocked">
			<MSBuild Projects="IsWorkstationLocked.dproj"/>
		</Target>
		<Target Name="IsWorkstationLocked:Clean">
			<MSBuild Projects="IsWorkstationLocked.dproj" Targets="Clean"/>
		</Target>
		<Target Name="IsWorkstationLocked:Make">
			<MSBuild Projects="IsWorkstationLocked.dproj" Targets="Make"/>
		</Target>
		<Target Name="FinalPathNameByHandle">
			<MSBuild Projects="FinalPathNameByHandle.dproj"/>
		</Target>
		<Target Name="FinalPathNameByHandle:Clean">
			<MSBuild Projects="FinalPathNameByHandle.dproj" Targets="Clean"/>
		</Target>
		<Target Name="FinalPathNameByHandle:Make">
			<MSBuild Projects="FinalPathNameByHandle.dproj" Targets="Make"/>
		</Target>
		<Target Name="Build">
			<CallTarget Targets="IsWorkstationLocked;FinalPathNameByHandle"/>
		</Target>
		<Target Name="Clean">
			<CallTarget Targets="IsWorkstationLocked:Clean;FinalPathNameByHandle:Clean"/>
		</Target>
		<Target Name="Make">
			<CallTarget Targets="IsWorkstationLocked:Make;FinalPathNameByHandle:Make"/>
		</Target>
		<Import Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')" Project="$(BDS)\Bin\CodeGear.Group.Targets"/>
	</Project>