• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Notifying a message in Action center.


Commit MetaInfo

Revisiónc1dbbbff3d59c672cfb431d754f85c25504b14f1 (tree)
Tiempo2021-05-02 13:33:52
AutorJeffyTS <JeffyTS@outl...>
CommiterJeffyTS

Log Message

2021/05/02

Cambiar Resumen

  • add: .vs/ProjectSettings.json (diff)
  • add: .vs/slnx.sqlite (diff)
  • delete: CtrlVIX/CtrlVIX.csproj
  • delete: CtrlVIX/CtrlVix.cs
  • delete: CtrlVIX/Properties/AssemblyInfo.cs
  • add: NotifyMessage.sln (diff)
  • add: NotifyMessage/MainForm.Designer.cs (diff)
  • add: NotifyMessage/MainForm.cs (diff)
  • add: NotifyMessage/NotifyMessage.ico (diff)
  • add: NotifyMessage/Program.cs (diff)
  • delete: VMwPlayerTaskTray/MainForm.Designer.cs
  • delete: VMwPlayerTaskTray/MainForm.cs
  • delete: VMwPlayerTaskTray/MainForm.resx => NotifyMessage/Properties/Resources.resx
  • delete: VMwPlayerTaskTray/MainFormSub.cs
  • delete: VMwPlayerTaskTray/Program.cs
  • delete: VMwPlayerTaskTray/Properties/Resources.resx => NotifyMessage/MainForm.resx
  • delete: VMwPlayerTaskTray/VMwPlayerTaskTray.csproj => NotifyMessage/NotifyMessage.csproj
  • delete: VMwPlayerTaskTray/VMwPlayerTaskTray.ico
  • delete: VMwPlayerTaskTray/VMwPlayerTaskTray_err.ico
  • delete: VMwPlayerTaskTray/VMwPlayerTaskTray_proc.ico
  • delete: VMwPlayerTaskTray/VMwPlayerTaskTray_run.ico
  • delete: VMwPlayerTaskTray/VMwPlayerTaskTray_stop.ico => NotifyMessage/NotifyMessageTray.ico
  • delete: VMwPlayerTaskTray/VMwPlayerTaskTray_suspend.ico
  • delete: {VMwPlayerTaskTray => NotifyMessage}/App.config
  • delete: {VMwPlayerTaskTray => NotifyMessage}/Properties/AssemblyInfo.cs
  • delete: {VMwPlayerTaskTray => NotifyMessage}/Properties/Resources.Designer.cs
  • delete: {VMwPlayerTaskTray => NotifyMessage}/Properties/Settings.Designer.cs
  • delete: {VMwPlayerTaskTray => NotifyMessage}/Properties/Settings.settings

Diferencia incremental

--- /dev/null
+++ b/.vs/ProjectSettings.json
@@ -0,0 +1,3 @@
1+{
2+ "CurrentProjectSetting": null
3+}
\ No newline at end of file
Binary files /dev/null and b/.vs/slnx.sqlite differ
--- a/CtrlVIX/CtrlVIX.csproj
+++ /dev/null
@@ -1,84 +0,0 @@
1-<?xml version="1.0" encoding="utf-8"?>
2-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3- <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4- <PropertyGroup>
5- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7- <ProjectGuid>{707AE0E6-AB93-4EE1-A708-BF95F91A3E30}</ProjectGuid>
8- <OutputType>Library</OutputType>
9- <AppDesignerFolder>Properties</AppDesignerFolder>
10- <RootNamespace>CtrlVIX</RootNamespace>
11- <AssemblyName>CtrlVIX</AssemblyName>
12- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13- <FileAlignment>512</FileAlignment>
14- </PropertyGroup>
15- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16- <DebugSymbols>true</DebugSymbols>
17- <DebugType>full</DebugType>
18- <Optimize>false</Optimize>
19- <OutputPath>bin\Debug\</OutputPath>
20- <DefineConstants>DEBUG;TRACE</DefineConstants>
21- <ErrorReport>prompt</ErrorReport>
22- <WarningLevel>4</WarningLevel>
23- </PropertyGroup>
24- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25- <DebugType>pdbonly</DebugType>
26- <Optimize>true</Optimize>
27- <OutputPath>bin\Release\</OutputPath>
28- <DefineConstants>TRACE</DefineConstants>
29- <ErrorReport>prompt</ErrorReport>
30- <WarningLevel>4</WarningLevel>
31- </PropertyGroup>
32- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
33- <DebugSymbols>true</DebugSymbols>
34- <OutputPath>bin\x64\Debug\</OutputPath>
35- <DefineConstants>DEBUG;TRACE</DefineConstants>
36- <DebugType>full</DebugType>
37- <PlatformTarget>x64</PlatformTarget>
38- <ErrorReport>prompt</ErrorReport>
39- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
40- </PropertyGroup>
41- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
42- <OutputPath>bin\x64\Release\</OutputPath>
43- <DefineConstants>TRACE</DefineConstants>
44- <Optimize>true</Optimize>
45- <DebugType>pdbonly</DebugType>
46- <PlatformTarget>x64</PlatformTarget>
47- <ErrorReport>prompt</ErrorReport>
48- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
49- </PropertyGroup>
50- <ItemGroup>
51- <Reference Include="System" />
52- <Reference Include="System.Core" />
53- <Reference Include="System.Management" />
54- <Reference Include="System.Windows.Forms" />
55- <Reference Include="System.Xml.Linq" />
56- <Reference Include="System.Data.DataSetExtensions" />
57- <Reference Include="Microsoft.CSharp" />
58- <Reference Include="System.Data" />
59- <Reference Include="System.Xml" />
60- </ItemGroup>
61- <ItemGroup>
62- <Compile Include="CtrlVix.cs" />
63- <Compile Include="Properties\AssemblyInfo.cs" />
64- </ItemGroup>
65- <ItemGroup>
66- <COMReference Include="VixCOM">
67- <Guid>{7A474EE3-0062-4239-AE91-134AC9BD5FD3}</Guid>
68- <VersionMajor>1</VersionMajor>
69- <VersionMinor>0</VersionMinor>
70- <Lcid>0</Lcid>
71- <WrapperTool>tlbimp</WrapperTool>
72- <Isolated>False</Isolated>
73- <EmbedInteropTypes>False</EmbedInteropTypes>
74- </COMReference>
75- </ItemGroup>
76- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
77- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
78- Other similar extension points exist, see Microsoft.Common.targets.
79- <Target Name="BeforeBuild">
80- </Target>
81- <Target Name="AfterBuild">
82- </Target>
83- -->
84-</Project>
\ No newline at end of file
--- a/CtrlVIX/CtrlVix.cs
+++ /dev/null
@@ -1,1005 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-using System.Threading.Tasks;
6-
7-using System.Windows.Forms; // Add
8-using System.Management; // Add
9-using System.Diagnostics; // Add
10-using VixCOM; // Add
11-using System.IO; // Add
12-using System.Text.RegularExpressions; // Add
13-
14-
15-
16-namespace CtrlVix
17-{
18- public static class Constants
19- {
20- public enum POWEROP : int // VMOperation()
21- {
22- POWER_ON_GUI,
23- POWER_ON_NOGUI,
24- SUSPEND,
25- ACPI_RESET,
26- ACPI_POWER_OFF,
27- HW_RESET,
28- HW_POWER_OFF
29- };
30- public enum VMSTATE : int // GetVMState()
31- {
32- POWERED_ON = 1,
33- PROCESSING,
34- POWERED_OFF,
35- ERROR = 0xffff
36- };
37- public enum RUNNING_MODE : int // CheckRunningMode()
38- {
39- CANNOT_DETERMINE = 0,
40- GUI,
41- NOGUI,
42- POWERED_OFF = 0xffff
43- };
44- public enum POWER_OFF_MODE : int // CheckPowerOffMode()
45- {
46- SUSPENDED,
47- POWERED_OFF,
48- ERROR = 0xffff
49- };
50- public enum TOOLS_RUNNING : int // CheckToolsRunnnging()
51- {
52- NOT_RUNNING,
53- RUNNING,
54- ERROR = 0xffff
55- };
56- public static string WORKINGDIR = "workingDir"; // GetVMWorkingDir()
57- public static string WORKINGDIR_ERR = "WORKINGDIR_ERR";
58- }
59-
60- public class CtrlVIX
61- {
62- public bool VMOperation(string vmxFilePath, CtrlVix.Constants.POWEROP powerOP)
63- {
64- VixCOM.IVixLib IVixLib = new VixCOM.VixLib();
65- VixCOM.IHost IHost;
66- VixCOM.IVM2 IVM;
67- VixCOM.IJob IJob;
68-
69- ulong err;
70-#if DEBUG
71- Debug.WriteLine("VIX: Start VMOperation.");
72-#endif
73- // Open the virtual machine and get a handle...
74- if ((IHost = GetHandle()) == null)
75- {
76- return false; // error
77- }
78- if ((IVM = OpenVM(IHost, vmxFilePath)) == null)
79- {
80- IHost.Disconnect();
81- return false; // error
82- }
83-#if DEBUG
84-// Debug.WriteLine("VIX: Start VIX command.");
85-#endif
86- switch (powerOP)
87- {
88- case Constants.POWEROP.POWER_ON_GUI:
89- IJob = IVM.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_LAUNCH_GUI, null, null);
90- break;
91- case Constants.POWEROP.POWER_ON_NOGUI:
92- IJob = IVM.PowerOn(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, null, null);
93- break;
94- case Constants.POWEROP.SUSPEND:
95- IJob = IVM.Suspend(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, null);
96- break;
97- case Constants.POWEROP.ACPI_RESET:
98- IJob = IVM.Reset(VixCOM.Constants.VIX_VMPOWEROP_FROM_GUEST, null);
99- break;
100- case Constants.POWEROP.ACPI_POWER_OFF:
101- IJob = IVM.PowerOff(VixCOM.Constants.VIX_VMPOWEROP_FROM_GUEST, null);
102- break;
103- case Constants.POWEROP.HW_RESET:
104- IJob = IVM.Reset(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, null);
105- break;
106- case Constants.POWEROP.HW_POWER_OFF:
107- IJob = IVM.PowerOff(VixCOM.Constants.VIX_VMPOWEROP_NORMAL, null);
108- break;
109- default:
110- return false;
111- }
112-#if DEBUG
113- Debug.WriteLine("VIX: Done VIX command.");
114-#endif
115- System.Threading.Thread.Sleep(1000); // 1sec wait
116- err = IJob.WaitWithoutResults();
117-#if DEBUG
118- Debug.WriteLine("VIX: Finish JobWaitWithoutResults.");
119-#endif
120- if (IVixLib.ErrorIndicatesFailure(err))
121- {
122- // VIX's bug? ACPI Reset/Power Offをしたとき3009エラーで実行されないことがある
123- if (((powerOP == Constants.POWEROP.ACPI_RESET) || (powerOP == Constants.POWEROP.ACPI_POWER_OFF))
124- && (IVixLib.ErrorCode(err) == VixCOM.Constants.VIX_E_POWEROP_SCRIPTS_NOT_AVAILABLE))
125- {
126- CloseVixObject(IJob);
127- CloseVixObject(IVM);
128- IHost.Disconnect();
129- /***
130- // 数回再実行する
131- for (int i = 1; i <= 5; i++)
132- {
133-#if DEBUG
134- Debug.WriteLine("VIX: ReRunVMControl x" + i.ToString("D"));
135-#endif
136- System.Threading.Thread.Sleep(5000); // 5sec wait
137- if (reRunVMOperation(vmxFilePath, powerOP)) return true;
138- // if (GetVMState(vmxFilePath) != Constants.VMSTATE.ERROR) return true;
139- }
140- ***/
141- // もう一度実行する
142-#if DEBUG
143- Debug.WriteLine("VIX: ReRunVMControl");
144-#endif
145- System.Threading.Thread.Sleep(5000); // 5sec wait
146- if (reRunVMOperation(vmxFilePath, powerOP)) return true;
147-
148- if (CheckToolsRunning(vmxFilePath) != Constants.TOOLS_RUNNING.RUNNING)
149- {
150- // toolが動いていないときはメッセージは表示するがエラーとはしない
151- ErrMessage(VixCOM.Constants.VIX_E_POWEROP_SCRIPTS_NOT_AVAILABLE);
152- return true;
153- }
154- // toolが動いてるときもメッセージは表示するがエラーとはしない
155- ErrMessage(VixCOM.Constants.VIX_E_TIMEOUT_WAITING_FOR_TOOLS);
156- return true;
157- }
158- // SUSPED させたとき VM_NOT_RUNNNINGはエラーとはしない
159- else if ((powerOP == Constants.POWEROP.SUSPEND) &&
160- (IVixLib.ErrorCode(err) == VixCOM.Constants.VIX_E_VM_NOT_RUNNING))
161- {
162- // NOP
163- }
164- // for Player 12.0.0 NOGUI させたとき VIX_E_CANCELLEDはメッセージは表示するがエラーとはしない
165- else if ((powerOP == Constants.POWEROP.POWER_ON_NOGUI) &&
166- (IVixLib.ErrorCode(err) == VixCOM.Constants.VIX_E_CANCELLED))
167- {
168- ErrMessage(err);
169- }
170- else
171- {
172- // Error Handler
173- ErrMessage(err);
174- CloseVixObject(IJob);
175- CloseVixObject(IVM);
176- IHost.Disconnect();
177- return false;
178- }
179- }
180- CloseVixObject(IJob);
181- CloseVixObject(IVM);
182- IHost.Disconnect();
183-#if DEBUG
184- Debug.WriteLine("VIX: Finish VMOperation.");
185-#endif
186- return true;
187- }
188-
189- private bool reRunVMOperation(string vmxFilePath, CtrlVix.Constants.POWEROP powerOP)
190- {
191- VixCOM.IVixLib IVixLib = new VixCOM.VixLib();
192- VixCOM.IHost IHost;
193- VixCOM.IVM2 IVM;
194- VixCOM.IJob IJob;
195-
196- ulong err;
197-#if DEBUG
198-// Debug.WriteLine("VIX: Re:Start VMOperation.");
199-#endif
200- // Open the virtual machine and get a handle...
201- if ((IHost = GetHandle()) == null)
202- {
203- return false; // error
204- }
205- if ((IVM = OpenVM(IHost, vmxFilePath)) == null)
206- {
207- IHost.Disconnect();
208- return false; // error
209- }
210-#if DEBUG
211-// Debug.WriteLine("VIX: Re:Start VIX command.");
212-#endif
213- switch (powerOP)
214- {
215- case Constants.POWEROP.ACPI_RESET:
216- IJob = IVM.Reset(VixCOM.Constants.VIX_VMPOWEROP_FROM_GUEST, null);
217- break;
218- case Constants.POWEROP.ACPI_POWER_OFF:
219- IJob = IVM.PowerOff(VixCOM.Constants.VIX_VMPOWEROP_FROM_GUEST, null);
220- break;
221- default:
222- return false;
223- }
224-#if DEBUG
225-// Debug.WriteLine("VIX: Re:Done VIX command.");
226-#endif
227- err = IJob.WaitWithoutResults();
228-#if DEBUG
229-// Debug.WriteLine("VIX: Re:Finish JobWaitWithoutResults.");
230-#endif
231- if (IVixLib.ErrorIndicatesFailure(err))
232- {
233- // Error Handler
234- CloseVixObject(IJob);
235- CloseVixObject(IVM);
236- IHost.Disconnect();
237- return false;
238- }
239- CloseVixObject(IJob);
240- CloseVixObject(IVM);
241- IHost.Disconnect();
242- return true;
243- }
244-
245- public Constants.VMSTATE GetVMState(string vmxFilePath)
246- {
247- // Processing (0x0895)
248- const int processing = VixCOM.Constants.VIX_POWERSTATE_POWERING_OFF // 0x0001
249- | VixCOM.Constants.VIX_POWERSTATE_POWERING_ON // 0x0004
250- | VixCOM.Constants.VIX_POWERSTATE_SUSPENDING // 0x0010
251- | VixCOM.Constants.VIX_POWERSTATE_RESETTING // 0x0080
252- | VixCOM.Constants.VIX_POWERSTATE_RESUMING; // 0x0800
253- // Unknown status (0x0300)
254- const int unknown = VixCOM.Constants.VIX_POWERSTATE_BLOCKED_ON_MSG // 0x0100
255- | VixCOM.Constants.VIX_POWERSTATE_PAUSED; // 0x0200
256- // Powered OFF (0x0022)
257- const int powered_off = VixCOM.Constants.VIX_POWERSTATE_POWERED_OFF // 0x0002
258- | VixCOM.Constants.VIX_POWERSTATE_SUSPENDED; // 0x0020
259- // Powered ON (0x0008)
260- const int powered_on = VixCOM.Constants.VIX_POWERSTATE_POWERED_ON; // 0x0008
261- // Tooles running (0x0040)
262- //const int tools_running = VixCOM.Constants.VIX_POWERSTATE_TOOLS_RUNNING; // 0x0040
263- // Undefined
264- //const int undefined = 0xffff ^ (processing | unknown | powered_off | powered_on | tools_running);
265-
266- int vmState;
267-
268- vmState = getVMState(vmxFilePath);
269- if (vmState == 0xffff)
270- {
271-#if DEBUG
272- Debug.WriteLine("VIX: Detect VMSTATE.ERROR");
273-#endif
274- return Constants.VMSTATE.ERROR; // error
275- }
276-/***
277-#if DEBUG
278- if ((vmState & undefined) != 0)
279- {
280- // 何もしない(debug)用
281- Debug.WriteLine("VIX: " + vmState.ToString("X") + " Detect undefined flag in vmstate.");
282- }
283- if ((vmState & tools_running) != 0)
284- {
285- // 何もしない(debug)用
286- Debug.WriteLine("VIX: Detect tools running flag in vmstate.");
287- }
288-#endif
289-***/
290- // Powered OFF
291- if ((vmState & powered_off) != 0)
292- {
293-#if DEBUG
294- if ((vmState & VixCOM.Constants.VIX_POWERSTATE_SUSPENDED) != 0)
295- {
296- Debug.WriteLine("VIX: Detect VIX_POWERSTATE_SUSPENDED.");
297- }
298-#endif
299- // VIXを長時間動かしているとPoweredOFFになってしまうバグの回避のため
300- if (CheckPowerOnByProcess(vmxFilePath))
301- {
302-#if DEBUG
303- Debug.WriteLine("VIX: Rewrite the vmState to power on cause of detecting the VIX's bug.");
304- Debug.WriteLine(" However, some cases go through this routing by remaining the process.");
305-#endif
306- vmState = (vmState ^ (vmState & powered_off)) | powered_on; // powered_offを落としてpowered_onを立てて後の処理に任せる
307- }
308- else return Constants.VMSTATE.POWERED_OFF; // Powered OFF
309- }
310- // Processing
311- if (( vmState & (processing | unknown)) != 0)
312- {
313-#if DEBUG
314- if ((vmState & VixCOM.Constants.VIX_POWERSTATE_BLOCKED_ON_MSG) != 0)
315- {
316- Debug.WriteLine("VIX: Detect VIX_POWERSTATE_BLOCKED_ON_MSG.");
317- }
318- if ((vmState & VixCOM.Constants.VIX_POWERSTATE_PAUSED) != 0)
319- {
320- Debug.WriteLine("VIX: Detect VIX_POWERSTATE_PAUSED.");
321- }
322- if ((vmState & VixCOM.Constants.VIX_POWERSTATE_RESUMING) != 0)
323- {
324- Debug.WriteLine("VIX: Detect VIX_POWERSTATE_RESUMING.");
325- }
326-#endif
327- return Constants.VMSTATE.PROCESSING; // Processing
328- }
329- // Powered ON
330- if ((vmState & powered_on) != 0)
331- {
332- return Constants.VMSTATE.POWERED_ON; // Powered ON
333- }
334- return Constants.VMSTATE.ERROR; // error
335- }
336-
337- public Constants.RUNNING_MODE CheckRunningMode(string vmxFilePath)
338- {
339- bool vmxflag = true;
340- string vmxName = Path.GetFileNameWithoutExtension(vmxFilePath); // VM 名を作成
341-
342- ManagementPath mngmntPath = new ManagementPath("Win32_Process");
343- ManagementClass mngmntClass = new ManagementClass(mngmntPath);
344-
345- ManagementObjectCollection mngmntObjClctn = mngmntClass.GetInstances();
346- foreach (ManagementObject obj in mngmntObjClctn)
347- {
348- object commandLineObj = obj["CommandLine"];
349- if (commandLineObj != null)
350- {
351- string commandLine = commandLineObj.ToString();
352- if (0 <= commandLine.IndexOf("vmplayer"))
353- {
354- if (0 <= commandLine.IndexOf(vmxName))
355- {
356- return Constants.RUNNING_MODE.GUI; // "vmplayer + vmxName" runnning
357- }
358- if (0 >= commandLine.IndexOf(".vmx"))
359- {
360- vmxflag = false;
361- }
362- }
363- }
364- }
365- if (!vmxflag)
366- {
367- return Constants.RUNNING_MODE.CANNOT_DETERMINE; // "vmplayer" only running
368- }
369- return Constants.RUNNING_MODE.NOGUI; // "vmplayer" not runnning or "vmplayer + other vmx" runnning
370- }
371-
372- public Constants.TOOLS_RUNNING CheckToolsRunning(string vmxFilePath)
373- {
374- int vmState;
375-
376- vmState = getVMState(vmxFilePath);
377- if (vmState == 0xffff)
378- {
379-#if DEBUG
380- Debug.WriteLine("VIX: Detect TOOLS_RUNNING.ERROR");
381-#endif
382- return Constants.TOOLS_RUNNING.ERROR; // error
383- }
384- if ((vmState & VixCOM.Constants.VIX_POWERSTATE_POWERED_ON) != 0)
385- {
386- if ((vmState & VixCOM.Constants.VIX_POWERSTATE_TOOLS_RUNNING) != 0)
387- {
388- return Constants.TOOLS_RUNNING.RUNNING;
389- }
390- }
391-#if DEBUG
392- Debug.WriteLine("VIX: Detect TOOLS_RUNNING.NOT_RUNNING");
393-#endif
394- return Constants.TOOLS_RUNNING.NOT_RUNNING;
395- }
396-
397- public Constants.POWER_OFF_MODE CheckPowerOffMode(string vmxFilePath)
398- {
399- int vmState;
400- string Dir;
401- string VMname;
402- string VMSSname;
403- string[] files;
404-
405- Dir = getVMWorkingDir(vmxFilePath);
406-
407- vmState = getVMState(vmxFilePath);
408- if (vmState == 0xffff)
409- {
410- return Constants.POWER_OFF_MODE.ERROR; // error
411- }
412- // VIXからこのフラグは戻らないようだが念のためチェックする
413- if ((vmState & VixCOM.Constants.VIX_POWERSTATE_SUSPENDED) != 0)
414- {
415-#if DEBUG
416- Debug.WriteLine("VIX: Returned VM Suspended flag.");
417-#endif
418- return Constants.POWER_OFF_MODE.SUSPENDED;
419- }
420- // suspend時に"VMXname-????????.vmss"ファイルが作成されることを利用して判定
421- // エラーでファイルが残った場合などはうまく判定できない可能性あり
422- VMname = Path.GetFileNameWithoutExtension(vmxFilePath);
423- VMSSname = VMname + "-*.vmss";
424- try
425- {
426- files = Directory.GetFiles(Dir, VMSSname, SearchOption.TopDirectoryOnly);
427- if (files.Length == 0)
428- {
429- return Constants.POWER_OFF_MODE.POWERED_OFF;
430- }
431- return Constants.POWER_OFF_MODE.SUSPENDED;
432- }
433- catch (IOException ex)
434- {
435-#if DEBUG
436- Debug.WriteLine("VIX: Catch System.IO.IOException");
437-#endif
438- MessageBox.Show("Inside CtrlVix error: " + ex.Message,
439- "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
440- return Constants.POWER_OFF_MODE.ERROR;
441- }
442- catch (Exception ex)
443- {
444-#if DEBUG
445- Debug.WriteLine("VIX: Catch System.Exception");
446-#endif
447- MessageBox.Show("Inside CtrlVix error: " + ex.Message,
448- "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
449- return Constants.POWER_OFF_MODE.ERROR;
450- }
451- }
452-
453- public int GetVMProcessID(string vmxFilePath)
454- {
455- string vmxName = Path.GetFileNameWithoutExtension(vmxFilePath); // VM 名を作成
456-
457- ManagementPath mngmntPath = new ManagementPath("Win32_Process");
458- ManagementClass mngmntClass = new ManagementClass(mngmntPath);
459-
460- ManagementObjectCollection mngmntObjClctn = mngmntClass.GetInstances();
461- foreach (ManagementObject obj in mngmntObjClctn)
462- {
463- object commandLineObj = obj["CommandLine"];
464- if (commandLineObj != null)
465- {
466- string commandLine = commandLineObj.ToString();
467- if (0 <= commandLine.IndexOf("vmplayer"))
468- {
469- if (0 <= commandLine.IndexOf(vmxName))
470- {
471- return int.Parse(obj["ProcessId"].ToString());
472- }
473- }
474- }
475- }
476- return 0;
477- }
478-
479- private int getVMState(string vmxFilePath)
480- {
481- // VMwareの動作状態をチェック
482- // These values are bitwise flags.
483- //const int VIX_POWERSTATE_POWERING_OFF = 0x0001;
484- // Indicates that VixVM_PowerOff() has been called, but the operation itself has not completed.
485- //const int VIX_POWERSTATE_POWERED_OFF = 0x0002;
486- // Indicates that the virtual machine is not running.
487- //const int VIX_POWERSTATE_POWERING_ON = 0x0004;
488- // Indicates that VixVM_PowerOn() has been called, but the operation itself has not completed.
489- //const int VIX_POWERSTATE_POWERED_ON = 0x0008;
490- // Indicates that the virtual machine is running.
491- //const int VIX_POWERSTATE_SUSPENDING = 0x0010;
492- // Indicates that VixVM_Suspend() has been called, but the operation itself has not completed.
493- //const int VIX_POWERSTATE_SUSPENDED = 0x0020;
494- // Indicates that the virtual machine is suspended. Use VixVM_PowerOn() to resume the virtual machine.
495- //const int VIX_POWERSTATE_TOOLS_RUNNING = 0x0040;
496- // Indicates that the virtual machine is running and the VMware Tools suite is active. See also the VixToolsState property.
497- //const int VIX_POWERSTATE_RESETTING = 0x0080;
498- // Indicates that VixVM_Reset() has been called, but the operation itself has not completed.
499- //const int VIX_POWERSTATE_BLOCKED_ON_MSG = 0x0100;
500- // Indicates that a virtual machine state change is blocked, waiting for user interaction
501- //const int VIX_POWERSTATE_PAUSED = 0x0200;
502- //const int VIX_POWERSTATE_RESUMING = 0x0800;
503-
504- // Get Properties
505- VixCOM.IVixLib IVixLib = new VixCOM.VixLib();
506- VixCOM.IHost IHost;
507- VixCOM.IVM2 IVM;
508- VixCOM.IVixHandle IVixHandle;
509-
510- ulong err;
511- object propertiesArray;
512- int[] propertyIDs;
513- int vmState;
514- int toolsState;
515-
516- // Open the virtual machine and get a handle...
517- if ((IHost = GetHandle()) == null)
518- {
519- return 0xffff; // error
520- }
521- if ((IVM = OpenVM(IHost, vmxFilePath)) == null)
522- {
523- IHost.Disconnect();
524- return 0xffff; // error
525- }
526- // Get Properties
527- // propertyIDs = new int[] { VixCOM.Constants.VIX_PROPERTY_VM_POWER_STATE,
528- // VixCOM.Constants.VIX_PROPERTY_VM_VMX_PATHNAME };
529- // propertyIDs = new int[] { VixCOM.Constants.VIX_PROPERTY_VM_POWER_STATE };
530- propertyIDs = new int[] { VixCOM.Constants.VIX_PROPERTY_VM_POWER_STATE,
531- VixCOM.Constants.VIX_PROPERTY_VM_TOOLS_STATE };
532- propertiesArray = null;
533- IVixHandle = (VixCOM.IVixHandle)IVM;
534- err = IVixHandle.GetProperties(propertyIDs, ref propertiesArray);
535- if (IVixLib.ErrorIndicatesFailure(err))
536- {
537- // Error Handler
538- ErrMessage(err);
539- CloseVixObject(IVM);
540- IHost.Disconnect();
541- return 0xffff; // error
542- }
543- vmState = (int)((object[])propertiesArray)[0]; // VixCOM.Constants.VIX_PROPERTY_VM_POWER_STATE
544- // vmPathName = (string)((object[])propertiesArray)[1]; // VixCOM.Constants.VIX_PROPERTY_VM_VMX_PATHNAME
545- toolsState = (int)((object[])propertiesArray)[1]; // VixCOM.Constants.VIX_PROPERTY_VM_TOOLS_STATE
546-#if DEBUG
547- // Debug.WriteLine("VIX: vmState = " + vmState.ToString("X") + " toolsState = " + toolsState.ToString("X"));
548-#endif
549- if ((toolsState & VixCOM.Constants.VIX_TOOLSSTATE_RUNNING) == VixCOM.Constants.VIX_TOOLSSTATE_RUNNING)
550- {
551- // POWER_STATEプロパティにTOOLS_RUNNINGが入ってこないので、TOOLS_STATEを見て手動でフラグを立てる
552- // ただし、正しくは判定されない。
553- vmState = vmState | VixCOM.Constants.VIX_POWERSTATE_TOOLS_RUNNING;
554- }
555- CloseVixObject(IVM);
556- IHost.Disconnect();
557- return vmState;
558- }
559-
560- private VixCOM.IHost GetHandle()
561- {
562- int vmxApiVersion = VixCOM.Constants.VIX_API_VERSION;
563- int vmxHostType = VixCOM.Constants.VIX_SERVICEPROVIDER_VMWARE_PLAYER;
564- string hostName = "";
565- string userName = "";
566- string password = "";
567-
568- VixCOM.IVixLib IVixLib = new VixCOM.VixLib();
569- VixCOM.IJob IJob;
570- VixCOM.IHost IHost;
571-
572- ulong err;
573- object propertiesArray;
574- int[] propertyIDs;
575-
576- // Open the virtual machine and get a handle...
577- IJob = IVixLib.Connect(vmxApiVersion, vmxHostType, hostName, 0, userName, password, 0, null, null);
578- propertiesArray = null;
579- propertyIDs = new int[] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE };
580- err = IJob.Wait(propertyIDs, ref propertiesArray);
581- if (IVixLib.ErrorIndicatesFailure(err))
582- {
583- // Error Handler
584- ErrMessage(err);
585- IHost = null;
586- }
587- else
588- {
589- IHost = (VixCOM.IHost)((object[])propertiesArray)[0];
590- CloseVixObject(IJob);
591- }
592- return IHost;
593- }
594-
595- private VixCOM.IVM2 OpenVM(VixCOM.IHost IHost, string vmxFilePath)
596- {
597- VixCOM.IVixLib IVixLib = new VixCOM.VixLib();
598- VixCOM.IJob IJob;
599- VixCOM.IVM2 IVM;
600-
601- ulong err;
602- object propertiesArray;
603- int[] propertyIDs;
604-
605- // Open the virtual machine
606- IJob = IHost.OpenVM(vmxFilePath, null);
607- propertiesArray = null;
608- propertyIDs = new int[] { VixCOM.Constants.VIX_PROPERTY_JOB_RESULT_HANDLE };
609- err = IJob.Wait(propertyIDs, ref propertiesArray);
610- if (IVixLib.ErrorIndicatesFailure(err))
611- {
612- // Error Handler
613- ErrMessage(err);
614- IVM = null;
615- }
616- else
617- {
618- IVM = (VixCOM.IVM2)((object[])propertiesArray)[0];
619- CloseVixObject(IJob);
620- }
621- return IVM;
622- }
623-
624- private static void CloseVixObject(Object vixObject)
625- {
626- try
627- {
628- ((VixCOM.IVixHandle2)vixObject).Close();
629- }
630- catch (Exception)
631- {
632- // Close is not supported in this version of Vix COM - Ignore
633- }
634- }
635-
636- private string getVMWorkingDir(string vmxFilePath)
637- {
638- foreach (var section in ReadVMX(vmxFilePath))
639- {
640- // section.Key は処理しない
641- foreach (var pair in section.Value)
642- {
643- if (pair.Key == Constants.WORKINGDIR_ERR) return Constants.WORKINGDIR_ERR;
644- if (pair.Key == Constants.WORKINGDIR) return (pair.Value.Substring(1, pair.Value.Length - 2));
645- }
646- }
647- return Path.GetDirectoryName(vmxFilePath);
648- }
649-
650- private static Dictionary<string, Dictionary<string, string>> ReadVMX(string file)
651- {
652- var sections = new Dictionary<string, Dictionary<string, string>>(StringComparer.Ordinal);
653- var regexSection = new Regex(@"^\s*\[(?<section>[^\]]+)\].*$", RegexOptions.Singleline
654- | RegexOptions.CultureInvariant);
655- var regexNameValue = new Regex(@"^\s*(?<name>[^=]+)=(?<value>.*?)(\s+;(?<comment>.*))?$",
656- RegexOptions.Singleline | RegexOptions.CultureInvariant);
657- var currentSection = string.Empty;
658-
659- // セクション名が明示されていない先頭部分のセクション名を""として扱う
660- sections[string.Empty] = new Dictionary<string, string>();
661- try
662- {
663- using (var reader = new StreamReader(file))
664- {
665- for (; ; )
666- {
667- var line = reader.ReadLine();
668-
669- if (line == null) break;
670- if (line.Length == 0) continue; // 空行は読み飛ばす
671- if (line.StartsWith(";", StringComparison.Ordinal)) continue; // ; コメント行は読み飛ばす
672- else if (line.StartsWith("#", StringComparison.Ordinal)) continue; // # コメント行は読み飛ばす
673-
674- var matchNameValue = regexNameValue.Match(line);
675- if (matchNameValue.Success)
676- {
677- sections[currentSection][matchNameValue.Groups["name"].Value.Trim()]
678- = matchNameValue.Groups["value"].Value.Trim(); // name=valueの行
679- continue;
680- }
681-
682- var matchSection = regexSection.Match(line);
683- if (matchSection.Success)
684- {
685- currentSection = matchSection.Groups["section"].Value; // [section]の行
686- if (!sections.ContainsKey(currentSection)) sections[currentSection]
687- = new Dictionary<string, string>(); continue;
688- }
689- }
690- return sections;
691- }
692- }
693- catch (IOException ex)
694- {
695-#if DEBUG
696- Debug.WriteLine("VIX: Catch System.IO.IOException");
697-#endif
698- MessageBox.Show("Inside CtrlVix error: " + ex.Message,
699- "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
700- sections[string.Empty][Constants.WORKINGDIR_ERR] = Constants.WORKINGDIR_ERR;
701- return sections;
702- }
703- catch (Exception ex)
704- {
705-#if DEBUG
706- Debug.WriteLine("VIX: Catch System.Exception");
707-#endif
708- MessageBox.Show("Inside CtrlVix error: " + ex.Message,
709- "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
710- sections[string.Empty][Constants.WORKINGDIR_ERR] = Constants.WORKINGDIR_ERR;
711- return sections;
712- }
713- }
714-
715- private void ErrMessage(ulong err)
716- {
717- VixCOM.IVixLib IVixLib = new VixCOM.VixLib();
718- string errMsg = IVixLib.GetErrorText(err, null);
719-#if DEBUG
720- // 文字化けのため実験
721- string a = IVixLib.GetErrorText(err, null);
722- string b = ConvertEncoding(a, Encoding.GetEncoding("shift_jis"), Encoding.UTF8);
723- string c = ConvertEncoding(a, Encoding.GetEncoding("unicode"), Encoding.UTF8);
724- string d = ConvertEncoding(a, Encoding.GetEncoding("utf-8"), Encoding.UTF8);
725- string e = ConvertEncoding(a, Encoding.GetEncoding("utf-32"), Encoding.UTF8);
726- string f = ConvertEncoding(a, Encoding.GetEncoding("shift_jis"), Encoding.Unicode);
727- string g = ConvertEncoding(a, Encoding.GetEncoding("unicode"), Encoding.Unicode);
728- string h = ConvertEncoding(a, Encoding.GetEncoding("utf-8"), Encoding.Unicode);
729- string i = ConvertEncoding(a, Encoding.GetEncoding("utf-32"), Encoding.Unicode);
730- string j = ConvertEncoding(a, Encoding.UTF8, Encoding.Unicode);
731- string k = ConvertEncoding(a, Encoding.Unicode, Encoding.UTF8);
732- string l = ConvertEncoding(a, Encoding.ASCII, Encoding.UTF8);
733-#endif
734- switch (err)
735- {
736-#if !DEBUG
737- case VixCOM.Constants.VIX_E_FAIL: // 1
738- errMsg = "VIX_E_FAIL";
739- break;
740- case VixCOM.Constants.VIX_E_OUT_OF_MEMORY: // 2
741- errMsg = "VIX_E_OUT_OF_MEMORY";
742- break;
743- case VixCOM.Constants.VIX_E_INVALID_ARG: // 3
744- errMsg = "VIX_E_INVALID_ARG";
745- break;
746- case VixCOM.Constants.VIX_E_FILE_NOT_FOUND: // 4
747- errMsg = "VIX_E_FILE_NOT_FOUND";
748- break;
749- case VixCOM.Constants.VIX_E_OBJECT_IS_BUSY: // 5
750- errMsg = "VIX_E_OBJECT_IS_BUSY";
751- break;
752- case VixCOM.Constants.VIX_E_NOT_SUPPORTED: // 6
753- errMsg = "VIX_E_NOT_SUPPORTED";
754- break;
755- case VixCOM.Constants.VIX_E_FILE_ERROR: // 7
756- errMsg = "VIX_E_FILE_ERROR";
757- break;
758- case VixCOM.Constants.VIX_E_DISK_FULL: // 8
759- errMsg = "VIX_E_DISK_FULL";
760- break;
761- case VixCOM.Constants.VIX_E_INCORRECT_FILE_TYPE: // 9
762- errMsg = "VIX_E_INCORRECT_FILE_TYPE";
763- break;
764-#endif
765- case VixCOM.Constants.VIX_E_CANCELLED: // 10
766- errMsg = "Operation cancelled.";
767- break;
768-#if !DEBUG
769- case VixCOM.Constants.VIX_E_FILE_READ_ONLY: // 11
770- errMsg = "VIX_E_FILE_READ_ONLY";
771- break;
772- case VixCOM.Constants.VIX_E_FILE_ALREADY_EXISTS: // 12
773- errMsg = "VIX_E_FILE_ALREADY_EXISTS";
774- break;
775- case VixCOM.Constants.VIX_E_FILE_ACCESS_ERROR: // 13
776- errMsg = "VIX_E_FILE_ACCESS_ERROR";
777- break;
778- case VixCOM.Constants.VIX_E_REQUIRES_LARGE_FILES: // 14
779- errMsg = "VIX_E_REQUIRES_LARGE_FILES";
780- break;
781- case VixCOM.Constants.VIX_E_FILE_ALREADY_LOCKED: // 15
782- errMsg = "VIX_E_FILE_ALREADY_LOCKED";
783- break;
784- case VixCOM.Constants.VIX_E_VMDB: // 16
785- errMsg = "VIX_E_VMDB";
786- break;
787- case VixCOM.Constants.VIX_E_NOT_SUPPORTED_ON_REMOTE_OBJECT: // 20
788- errMsg = "VIX_E_NOT_SUPPORTED_ON_REMOTE_OBJECT";
789- break;
790- case VixCOM.Constants.VIX_E_FILE_TOO_BIG: // 21
791- errMsg = "VIX_E_FILE_TOO_BIG";
792- break;
793- case VixCOM.Constants.VIX_E_FILE_NAME_INVALID: // 22
794- errMsg = "VIX_E_FILE_NAME_INVALID";
795- break;
796- case VixCOM.Constants.VIX_E_ALREADY_EXISTS: // 23
797- errMsg = "VIX_E_ALREADY_EXISTS";
798- break;
799- case VixCOM.Constants.VIX_E_BUFFER_TOOSMALL: // 24
800- errMsg = "VIX_E_BUFFER_TOOSMALL";
801- break;
802- case VixCOM.Constants.VIX_E_OBJECT_NOT_FOUND: // 25
803- errMsg = "VIX_E_OBJECT_NOT_FOUND";
804- break;
805- case VixCOM.Constants.VIX_E_HOST_NOT_CONNECTED: // 26
806- errMsg = "VIX_E_HOST_NOT_CONNECTED";
807- break;
808- case VixCOM.Constants.VIX_E_INVALID_UTF8_STRING: // 27
809- errMsg = "VIX_E_INVALID_UTF8_STRING";
810- break;
811- case VixCOM.Constants.VIX_E_OPERATION_ALREADY_IN_PROGRESS: // 31
812- errMsg = "VIX_E_OPERATION_ALREADY_IN_PROGRESS";
813- break;
814- case VixCOM.Constants.VIX_E_UNFINISHED_JOB: // 29
815- errMsg = "VIX_E_UNFINISHED_JOB";
816- break;
817- case VixCOM.Constants.VIX_E_NEED_KEY: // 30
818- errMsg = "VIX_E_NEED_KEY";
819- break;
820- case VixCOM.Constants.VIX_E_LICENSE: // 32
821- errMsg = "VIX_E_LICENSE";
822- break;
823- case VixCOM.Constants.VIX_E_VM_HOST_DISCONNECTED: // 34
824- errMsg = "VIX_E_VM_HOST_DISCONNECTED";
825- break;
826- case VixCOM.Constants.VIX_E_AUTHENTICATION_FAIL: // 35
827- errMsg = "VIX_E_AUTHENTICATION_FAIL";
828- break;
829- case VixCOM.Constants.VIX_E_HOST_CONNECTION_LOST: // 36
830- errMsg = "VIX_E_HOST_CONNECTION_LOST";
831- break;
832- case VixCOM.Constants.VIX_E_DUPLICATE_NAME: // 41
833- errMsg = "ConVIX_E_DUPLICATE_NAME";
834- break;
835- case VixCOM.Constants.VIX_E_ARGUMENT_TOO_BIG: // 44
836- errMsg = "VIX_E_ARGUMENT_TOO_BIG";
837- break;
838-#endif
839- case VixCOM.Constants.VIX_E_TIMEOUT_WAITING_FOR_TOOLS: // 3000
840- errMsg = "Power operation has not been able to be completed.";
841- break;
842-#if !DEBUG
843- case VixCOM.Constants.VIX_E_UNRECOGNIZED_COMMAND: // 3001
844- errMsg = "VIX_E_UNRECOGNIZED_COMMAND";
845- break;
846- case VixCOM.Constants.VIX_E_OP_NOT_SUPPORTED_ON_GUEST: // 3003
847- errMsg = "VIX_E_OP_NOT_SUPPORTED_ON_GUEST";
848- break;
849- case VixCOM.Constants.VIX_E_PROGRAM_NOT_STARTED: // 3004
850- errMsg = "VIX_E_PROGRAM_NOT_STARTED";
851- break;
852- case VixCOM.Constants.VIX_E_CANNOT_START_READ_ONLY_VM: // 3005
853- errMsg = "VIX_E_CANNOT_START_READ_ONLY_VM";
854- break;
855- case VixCOM.Constants.VIX_E_VM_NOT_RUNNING: // 3006
856- errMsg = "VIX_E_VM_NOT_RUNNING";
857- break;
858- case VixCOM.Constants.VIX_E_VM_IS_RUNNING: // 3007
859- errMsg = "VIX_E_VM_IS_RUNNING";
860- break;
861- case VixCOM.Constants.VIX_E_CANNOT_CONNECT_TO_VM: // 3008
862- errMsg = "VIX_E_CANNOT_CONNECT_TO_VM";
863- break;
864-#endif
865- case VixCOM.Constants.VIX_E_POWEROP_SCRIPTS_NOT_AVAILABLE: // 3009
866- errMsg = "VMware Tools are NOT running or NOT installed properly.";
867- break;
868-#if !DEBUG
869- case VixCOM.Constants.VIX_E_NO_GUEST_OS_INSTALLED: // 3010
870- errMsg = "VIX_E_NO_GUEST_OS_INSTALLED";
871- break;
872- case VixCOM.Constants.VIX_E_VM_INSUFFICIENT_HOST_MEMORY: // 3011
873- errMsg = "VIX_E_VM_INSUFFICIENT_HOST_MEMORY";
874- break;
875- case VixCOM.Constants.VIX_E_SUSPEND_ERROR: // 3012
876- errMsg = "VIX_E_SUSPEND_ERROR";
877- break;
878- case VixCOM.Constants.VIX_E_VM_NOT_ENOUGH_CPUS: // 3013
879- errMsg = "VIX_E_VM_NOT_ENOUGH_CPUS";
880- break;
881- case VixCOM.Constants.VIX_E_HOST_USER_PERMISSIONS: // 3014
882- errMsg = "VIX_E_HOST_USER_PERMISSIONS";
883- break;
884- case VixCOM.Constants.VIX_E_GUEST_USER_PERMISSIONS: // 3015
885- errMsg = "VIX_E_GUEST_USER_PERMISSIONS";
886- break;
887- case VixCOM.Constants.VIX_E_TOOLS_NOT_RUNNING: // 3016
888- errMsg = "VIX_E_TOOLS_NOT_RUNNING";
889- break;
890- case VixCOM.Constants.VIX_E_GUEST_OPERATIONS_PROHIBITED: // 3017
891- errMsg = "VIX_E_GUEST_OPERATIONS_PROHIBITED";
892- break;
893- case VixCOM.Constants.VIX_E_ANON_GUEST_OPERATIONS_PROHIBITED: // 3018
894- errMsg = "VIX_E_ANON_GUEST_OPERATIONS_PROHIBITED";
895- break;
896- case VixCOM.Constants.VIX_E_ROOT_GUEST_OPERATIONS_PROHIBITED: // 3019
897- errMsg = "VIX_E_ROOT_GUEST_OPERATIONS_PROHIBITED";
898- break;
899- case VixCOM.Constants.VIX_E_MISSING_ANON_GUEST_ACCOUNT: // 3023
900- errMsg = "VIX_E_MISSING_ANON_GUEST_ACCOUNT";
901- break;
902- case VixCOM.Constants.VIX_E_CANNOT_AUTHENTICATE_WITH_GUEST: // 3024
903- errMsg = "VIX_E_CANNOT_AUTHENTICATE_WITH_GUEST";
904- break;
905- case VixCOM.Constants.VIX_E_UNRECOGNIZED_COMMAND_IN_GUEST: // 3025
906- errMsg = "VIX_E_UNRECOGNIZED_COMMAND_IN_GUEST";
907- break;
908- case VixCOM.Constants.VIX_E_CONSOLE_GUEST_OPERATIONS_PROHIBITED: // 3026
909- errMsg = "VIX_E_CONSOLE_GUEST_OPERATIONS_PROHIBITED";
910- break;
911- case VixCOM.Constants.VIX_E_MUST_BE_CONSOLE_USER: // 3027
912- errMsg = "VIX_E_MUST_BE_CONSOLE_USER";
913- break;
914- case VixCOM.Constants.VIX_E_VMX_MSG_DIALOG_AND_NO_UI: // 3028
915- errMsg = "VIX_E_VMX_MSG_DIALOG_AND_NO_UI";
916- break;
917- case VixCOM.Constants.VIX_E_OPERATION_NOT_ALLOWED_FOR_LOGIN_TYPE: // 3031
918- errMsg = "VIX_E_OPERATION_NOT_ALLOWED_FOR_LOGIN_TYPE";
919- break;
920- case VixCOM.Constants.VIX_E_LOGIN_TYPE_NOT_SUPPORTED: // 3032
921- errMsg = "VIX_E_LOGIN_TYPE_NOT_SUPPORTED";
922- break;
923- case VixCOM.Constants.VIX_E_EMPTY_PASSWORD_NOT_ALLOWED_IN_GUEST: // 3033
924- errMsg = "VIX_E_EMPTY_PASSWORD_NOT_ALLOWED_IN_GUEST";
925- break;
926- case VixCOM.Constants.VIX_E_INTERACTIVE_SESSION_NOT_PRESENT: // 3034
927- errMsg = "VIX_E_INTERACTIVE_SESSION_NOT_PRESENT";
928- break;
929- case VixCOM.Constants.VIX_E_INTERACTIVE_SESSION_USER_MISMATCH: // 3035
930- errMsg = "VIX_E_INTERACTIVE_SESSION_USER_MISMATCH";
931- break;
932- case VixCOM.Constants.VIX_E_CANNOT_POWER_ON_VM: // 3041
933- errMsg = "VIX_E_CANNOT_POWER_ON_VM";
934- break;
935- case VixCOM.Constants.VIX_E_NO_DISPLAY_SERVER: // 3043
936- errMsg = "VIX_E_NO_DISPLAY_SERVER";
937- break;
938- case VixCOM.Constants.VIX_E_TOO_MANY_LOGONS: // 3046
939- errMsg = "VIX_E_TOO_MANY_LOGONS";
940- break;
941- case VixCOM.Constants.VIX_E_INVALID_AUTHENTICATION_SESSION: // 3047
942- errMsg = "VIX_E_INVALID_AUTHENTICATION_SESSION";
943- break;
944-#endif
945- case VixCOM.Constants.VIX_E_VM_NOT_FOUND: // 4000
946-#if DEBUG
947- Debug.WriteLine("VIX: VIX file not found");
948-#endif
949- break; // vix file not found の時は無視する
950- default:
951-#if !DEBUG
952- errMsg = "Inside VIX error.";
953-#endif
954- break;
955- }
956- MessageBox.Show("Inside VIX error: " + IVixLib.ErrorCode(err).ToString("D")
957- + " : " + errMsg,
958- "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
959- }
960-
961-#if DEBUG
962- private string ConvertEncoding(string src, Encoding srcEnc, Encoding destEnc)
963- {
964- byte[] src_temp = srcEnc.GetBytes(src);
965- byte[] dest_temp = Encoding.Convert(srcEnc, destEnc, src_temp);
966- string ret = destEnc.GetString(dest_temp);
967- return ret;
968- }
969-
970- private string ConvertEncoding2(string src, Encoding srcEnc)
971- {
972- byte[] src_temp = Encoding.ASCII.GetBytes(src);
973- byte[] dest_temp = Encoding.Convert(srcEnc, Encoding.UTF8, src_temp);
974- string ret = srcEnc.GetString(dest_temp);
975- return ret;
976- }
977-#endif
978-
979- private bool CheckPowerOnByProcess(string vmxFilePath)
980- {
981- string vmxName = Path.GetFileNameWithoutExtension(vmxFilePath); // VM 名を作成
982-
983- ManagementPath mngmntPath = new ManagementPath("Win32_Process");
984- ManagementClass mngmntClass = new ManagementClass(mngmntPath);
985-
986- ManagementObjectCollection mngmntObjClctn = mngmntClass.GetInstances();
987- foreach (ManagementObject obj in mngmntObjClctn)
988- {
989- object commandLineObj = obj["CommandLine"];
990- if (commandLineObj != null)
991- {
992- string commandLine = commandLineObj.ToString();
993- if (0 <= commandLine.IndexOf("vmware-vmx"))
994- {
995- if (0 <= commandLine.IndexOf(vmxName))
996- {
997- return true; // "vmware-vmx + vmxName" runnning = Powered ON
998- }
999- }
1000- }
1001- }
1002- return false; // "vmware-vmx + vmxName" not runnning = Powered OFF
1003- }
1004- }
1005-}
--- a/CtrlVIX/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
1-using System.Reflection;
2-using System.Runtime.CompilerServices;
3-using System.Runtime.InteropServices;
4-
5-// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
6-// アセンブリに関連付けられている情報を変更するには、
7-// これらの属性値を変更してください。
8-[assembly: AssemblyTitle("CtrlVIX")]
9-[assembly: AssemblyDescription("")]
10-[assembly: AssemblyConfiguration("")]
11-[assembly: AssemblyCompany("")]
12-[assembly: AssemblyProduct("CtrlVIX")]
13-[assembly: AssemblyCopyright("Copyright © 2014-2015 JeffyTS All rights reserved.")]
14-[assembly: AssemblyTrademark("")]
15-[assembly: AssemblyCulture("")]
16-
17-// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから
18-// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、
19-// その型の ComVisible 属性を true に設定してください。
20-[assembly: ComVisible(false)]
21-
22-// 次の GUID は、このプロジェクトが COM に公開される場合の、typelib の ID です
23-[assembly: Guid("21d6ee20-1881-4f38-aa80-9470eb37d85d")]
24-
25-// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
26-//
27-// Major Version
28-// Minor Version
29-// Build Number
30-// Revision
31-//
32-// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
33-// 既定値にすることができます:
34-// [assembly: AssemblyVersion("1.0.*")]
35-[assembly: AssemblyVersion("1.1.1.*")]
36-[assembly: AssemblyFileVersion("1.1.1.0")]
--- /dev/null
+++ b/NotifyMessage.sln
@@ -0,0 +1,29 @@
1+
2+Microsoft Visual Studio Solution File, Format Version 12.00
3+# Visual Studio 14
4+VisualStudioVersion = 14.0.23107.0
5+MinimumVisualStudioVersion = 10.0.40219.1
6+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NotifyMessage", "NotifyMessage\NotifyMessage.csproj", "{1BF662DF-003B-43F9-9E1F-C5FA0CF8092F}"
7+EndProject
8+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{41622DD9-5228-4CF2-867B-4BDF158BCFF4}"
9+ ProjectSection(SolutionItems) = preProject
10+ NotifyMessage\NotifyMessage.ico = NotifyMessage\NotifyMessage.ico
11+ NotifyMessage\NotifyMessageTray.ico = NotifyMessage\NotifyMessageTray.ico
12+ readme.txt = readme.txt
13+ EndProjectSection
14+EndProject
15+Global
16+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+ Debug|Any CPU = Debug|Any CPU
18+ Release|Any CPU = Release|Any CPU
19+ EndGlobalSection
20+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+ {1BF662DF-003B-43F9-9E1F-C5FA0CF8092F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+ {1BF662DF-003B-43F9-9E1F-C5FA0CF8092F}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+ {1BF662DF-003B-43F9-9E1F-C5FA0CF8092F}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+ {1BF662DF-003B-43F9-9E1F-C5FA0CF8092F}.Release|Any CPU.Build.0 = Release|Any CPU
25+ EndGlobalSection
26+ GlobalSection(SolutionProperties) = preSolution
27+ HideSolutionNode = FALSE
28+ EndGlobalSection
29+EndGlobal
--- a/VMwPlayerTaskTray/App.config
+++ b/NotifyMessage/App.config
@@ -1,6 +1,6 @@
11 <?xml version="1.0" encoding="utf-8" ?>
22 <configuration>
33 <startup>
4- <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
4+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
55 </startup>
66 </configuration>
\ No newline at end of file
--- /dev/null
+++ b/NotifyMessage/MainForm.Designer.cs
@@ -0,0 +1,58 @@
1+namespace NotifyMessage
2+{
3+ partial class MainForm
4+ {
5+ /// <summary>
6+ /// 必要なデザイナー変数です。
7+ /// </summary>
8+ private System.ComponentModel.IContainer components = null;
9+
10+ /// <summary>
11+ /// 使用中のリソースをすべてクリーンアップします。
12+ /// </summary>
13+ /// <param name="disposing">マネージ リソースを破棄する場合は true を指定し、その他の場合は false を指定します。</param>
14+ protected override void Dispose(bool disposing)
15+ {
16+ if (disposing && (components != null))
17+ {
18+ components.Dispose();
19+ }
20+ base.Dispose(disposing);
21+ }
22+
23+ #region Windows フォーム デザイナーで生成されたコード
24+
25+ /// <summary>
26+ /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
27+ /// コード エディターで変更しないでください。
28+ /// </summary>
29+ private void InitializeComponent()
30+ {
31+ this.components = new System.ComponentModel.Container();
32+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
33+ this.notifyIcon_MainForm = new System.Windows.Forms.NotifyIcon(this.components);
34+ this.SuspendLayout();
35+ //
36+ // notifyIcon_MainForm
37+ //
38+ this.notifyIcon_MainForm.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon_MainForm.Icon")));
39+ this.notifyIcon_MainForm.Text = "NotifyMessage";
40+ this.notifyIcon_MainForm.Visible = true;
41+ //
42+ // MainForm
43+ //
44+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
45+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
46+ this.ClientSize = new System.Drawing.Size(284, 261);
47+ this.Name = "MainForm";
48+ this.Text = "NotifyMessage";
49+ this.ResumeLayout(false);
50+
51+ }
52+
53+ #endregion
54+
55+ private System.Windows.Forms.NotifyIcon notifyIcon_MainForm;
56+ }
57+}
58+
--- /dev/null
+++ b/NotifyMessage/MainForm.cs
@@ -0,0 +1,117 @@
1+using System;
2+using System.Collections.Generic;
3+using System.ComponentModel;
4+using System.Data;
5+using System.Drawing;
6+using System.Linq;
7+using System.Text;
8+using System.Threading.Tasks;
9+using System.Windows.Forms;
10+using System.Reflection; // Add
11+
12+
13+
14+namespace NotifyMessage
15+{
16+ public partial class MainForm : Form
17+ {
18+ // This Program Name
19+ private const string PROGRAM_NAME = "NotifyMessage";
20+ // Messages
21+ private const string MSG_USAGE = "Notifiying a message in Action center.\r\n" +
22+ "\r\n" +
23+ " Usage: \r\n" +
24+ " " + PROGRAM_NAME + ".exe [opt] \"Your message\"\r\n" +
25+ "\r\n" +
26+ " Option:\r\n" +
27+ " /INFO(default) | /WARN | /ERR";
28+ private const string MSG_ABOUT = "Thanks to Microsoft Corporation.\r\n" +
29+ "\r\n" +
30+ "This program has been developed on\r\n" +
31+ " Visual Studio Community 2015\r\n" +
32+ " Windows10 Professional 64bit.\r\n" +
33+ "\r\n" +
34+ MSG_USAGE;
35+
36+ public MainForm()
37+ {
38+ // Messageはここで出さないと終了処理がうまくいかない(プロセスが残る)
39+ if (Program.Message == "")
40+ {
41+ //MessageBox.Show(MSG_USAGE, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
42+ AboutDialog();
43+ Program.Message = ""; // 消してしまう(flag代わり)
44+ }
45+ else if (Program.Message != "") // vmxFilePathが指定されていないときは初期化せず終了
46+ {
47+ InitializeComponent();
48+
49+ this.notifyIcon_MainForm.Text = PROGRAM_NAME; // Program.NotifyMessage;
50+ this.notifyIcon_MainForm.BalloonTipText = Program.Message;
51+ this.notifyIcon_MainForm.Icon = Properties.Resources.NotifyMessageTray;
52+
53+ switch (Program.msglevel)
54+ {
55+ case Program.MSGLEVEL.INFO:
56+ this.notifyIcon_MainForm.BalloonTipIcon = ToolTipIcon.Info;
57+ break;
58+ case Program.MSGLEVEL.WARN:
59+ this.notifyIcon_MainForm.BalloonTipIcon = ToolTipIcon.Warning;
60+ break;
61+ case Program.MSGLEVEL.ERR:
62+ this.notifyIcon_MainForm.BalloonTipIcon = ToolTipIcon.Error;
63+ break;
64+ default:
65+ this.notifyIcon_MainForm.BalloonTipIcon = ToolTipIcon.None;
66+ break;
67+ }
68+
69+ this.notifyIcon_MainForm.ShowBalloonTip(5000); // Balloon tip 表示
70+
71+ System.Threading.Thread.Sleep(5000);
72+
73+ // Exit
74+ this.notifyIcon_MainForm.Visible = false; // タスクトレイからアイコンを取り除く
75+ Application.Exit(); // アプリケーション終了
76+ }
77+ }
78+
79+ private void AboutDialog()
80+ {
81+ string message;
82+
83+ //AssemblyTitleの取得
84+ AssemblyTitleAttribute asmTitle = (AssemblyTitleAttribute)Attribute.GetCustomAttribute(
85+ Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute));
86+ //AssemblyDescriptionの取得
87+ AssemblyDescriptionAttribute asmDesc = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
88+ Assembly.GetExecutingAssembly(), typeof(AssemblyDescriptionAttribute));
89+ //AssemblyCompanyの取得
90+ AssemblyCompanyAttribute asmCompany = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(
91+ Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute));
92+ //AssemblyProductの取得
93+ AssemblyProductAttribute asmPrdct = (AssemblyProductAttribute)Attribute.GetCustomAttribute(
94+ Assembly.GetExecutingAssembly(), typeof(AssemblyProductAttribute));
95+ //AssemblyCopyrightの取得
96+ AssemblyCopyrightAttribute asmCpyrght = (AssemblyCopyrightAttribute)Attribute.GetCustomAttribute(
97+ Assembly.GetExecutingAssembly(), typeof(AssemblyCopyrightAttribute));
98+ //AssemblyTrademarkの取得
99+ AssemblyTrademarkAttribute asmTM = (AssemblyTrademarkAttribute)Attribute.GetCustomAttribute(
100+ Assembly.GetExecutingAssembly(), typeof(AssemblyTrademarkAttribute));
101+ //バージョンの取得
102+ Assembly asm = Assembly.GetExecutingAssembly();
103+ Version ver = asm.GetName().Version;
104+
105+ message = asmTitle.Title + "\r\n" +
106+ "\r\n" +
107+ asmDesc.Description + "\r\n" +
108+ "\r\n" +
109+ MSG_ABOUT + "\r\n" +
110+ "\r\n" +
111+ asmCompany.Company + "\r\n" +
112+ asmPrdct.Product + " Rev. " + ver + "\r\n" +
113+ asmCpyrght.Copyright + "\r\n";
114+ MessageBox.Show(message, PROGRAM_NAME, MessageBoxButtons.OK, MessageBoxIcon.Information);
115+ }
116+ }
117+}
--- a/VMwPlayerTaskTray/Properties/Resources.resx
+++ b/NotifyMessage/MainForm.resx
@@ -117,26 +117,36 @@
117117 <resheader name="writer">
118118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119 </resheader>
120- <data name="VMwPlayerTaskTray" xml:space="preserve">
121- <value />
122- </data>
123- <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
124- <data name="VMwPlayerTaskTray_err" type="System.Resources.ResXFileRef, System.Windows.Forms">
125- <value>..\VMwPlayerTaskTray_err.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
126- </data>
127- <data name="VMwPlayerTaskTray_ico" type="System.Resources.ResXFileRef, System.Windows.Forms">
128- <value>..\VMwPlayerTaskTray.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
129- </data>
130- <data name="VMwPlayerTaskTray_proc" type="System.Resources.ResXFileRef, System.Windows.Forms">
131- <value>..\VMwPlayerTaskTray_proc.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
132- </data>
133- <data name="VMwPlayerTaskTray_run" type="System.Resources.ResXFileRef, System.Windows.Forms">
134- <value>..\VMwPlayerTaskTray_run.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
135- </data>
136- <data name="VMwPlayerTaskTray_stop" type="System.Resources.ResXFileRef, System.Windows.Forms">
137- <value>..\VMwPlayerTaskTray_stop.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
138- </data>
139- <data name="VMwPlayerTaskTray_suspend" type="System.Resources.ResXFileRef, System.Windows.Forms">
140- <value>..\VMwPlayerTaskTray_suspend.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
120+ <metadata name="notifyIcon_MainForm.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+ <value>17, 17</value>
122+ </metadata>
123+ <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
124+ <data name="notifyIcon_MainForm.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
125+ <value>
126+ AAABAAEAEBAAAAEACABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
127+ AAD0fVEAAAAAAP///wBLS/0Aenp6ALABAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
128+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
129+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
130+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
131+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
132+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
133+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
134+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
135+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
136+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
137+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
138+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
139+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
140+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
141+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
142+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
143+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
144+ AAAAAAAABQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUAAAAAAAAAAAAABAQEBAQEAAEBAQEB
145+ AQEBAQQEBAQEBAABAwMBAQEBAQEBAQEBAQEAAQMDAQICAgIBAQEBAQEBAAEBAQEBAQEBAQEBAQEBAQAA
146+ AAAAAAAAAAABAQEBAQEAAAAAAAAAAAAAAQEBAQEBAAAAAAAAAAAAAAEBAQEBAQAAAAAAAAAAAAABAQEB
147+ AQEAAAAAAAAAAAAAAQEBAQEBAAAAAAAAAAAAAAEBAQEBAQAAAAAAAAAAAAABAgICAgEAAAAAAAAAAAAA
148+ AQEBAQEBAAAAAAAAAAAAAAEBAQEBAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
149+ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
150+</value>
141151 </data>
142152 </root>
\ No newline at end of file
--- a/VMwPlayerTaskTray/VMwPlayerTaskTray.csproj
+++ b/NotifyMessage/NotifyMessage.csproj
@@ -1,31 +1,17 @@
11 <?xml version="1.0" encoding="utf-8"?>
2-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33 <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44 <PropertyGroup>
55 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7- <ProjectGuid>{E132DACE-6C8E-4A09-BB02-1F2FBD4698A9}</ProjectGuid>
7+ <ProjectGuid>{1BF662DF-003B-43F9-9E1F-C5FA0CF8092F}</ProjectGuid>
88 <OutputType>WinExe</OutputType>
99 <AppDesignerFolder>Properties</AppDesignerFolder>
10- <RootNamespace>VMwPlayerTaskTray</RootNamespace>
11- <AssemblyName>VMwPlayerTaskTray</AssemblyName>
12- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
10+ <RootNamespace>NotifyMessage</RootNamespace>
11+ <AssemblyName>NotifyMessage</AssemblyName>
12+ <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1313 <FileAlignment>512</FileAlignment>
14- <IsWebBootstrapper>false</IsWebBootstrapper>
15- <PublishUrl>publish\</PublishUrl>
16- <Install>true</Install>
17- <InstallFrom>Disk</InstallFrom>
18- <UpdateEnabled>false</UpdateEnabled>
19- <UpdateMode>Foreground</UpdateMode>
20- <UpdateInterval>7</UpdateInterval>
21- <UpdateIntervalUnits>Days</UpdateIntervalUnits>
22- <UpdatePeriodically>false</UpdatePeriodically>
23- <UpdateRequired>false</UpdateRequired>
24- <MapFileExtensions>true</MapFileExtensions>
25- <ApplicationRevision>4</ApplicationRevision>
26- <ApplicationVersion>1.2.3.%2a</ApplicationVersion>
27- <UseApplicationTrust>false</UseApplicationTrust>
28- <BootstrapperEnabled>true</BootstrapperEnabled>
14+ <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
2915 </PropertyGroup>
3016 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
3117 <PlatformTarget>AnyCPU</PlatformTarget>
@@ -47,45 +33,22 @@
4733 <WarningLevel>4</WarningLevel>
4834 </PropertyGroup>
4935 <PropertyGroup>
50- <ApplicationIcon>VMwPlayerTaskTray.ico</ApplicationIcon>
51- </PropertyGroup>
52- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
53- <DebugSymbols>true</DebugSymbols>
54- <OutputPath>bin\x64\Debug\</OutputPath>
55- <DefineConstants>DEBUG;TRACE</DefineConstants>
56- <DebugType>full</DebugType>
57- <PlatformTarget>x64</PlatformTarget>
58- <ErrorReport>prompt</ErrorReport>
59- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
60- <Prefer32Bit>true</Prefer32Bit>
61- </PropertyGroup>
62- <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
63- <OutputPath>bin\x64\Release\</OutputPath>
64- <DefineConstants>TRACE</DefineConstants>
65- <Optimize>true</Optimize>
66- <DebugType>pdbonly</DebugType>
67- <PlatformTarget>x64</PlatformTarget>
68- <ErrorReport>prompt</ErrorReport>
69- <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
70- <Prefer32Bit>true</Prefer32Bit>
36+ <ApplicationIcon>NotifyMessage.ico</ApplicationIcon>
7137 </PropertyGroup>
7238 <ItemGroup>
7339 <Reference Include="System" />
7440 <Reference Include="System.Core" />
75- <Reference Include="System.Management" />
7641 <Reference Include="System.Xml.Linq" />
7742 <Reference Include="System.Data.DataSetExtensions" />
7843 <Reference Include="Microsoft.CSharp" />
7944 <Reference Include="System.Data" />
8045 <Reference Include="System.Deployment" />
8146 <Reference Include="System.Drawing" />
47+ <Reference Include="System.Net.Http" />
8248 <Reference Include="System.Windows.Forms" />
8349 <Reference Include="System.Xml" />
8450 </ItemGroup>
8551 <ItemGroup>
86- <Compile Include="MainFormSub.cs">
87- <SubType>Form</SubType>
88- </Compile>
8952 <Compile Include="MainForm.cs">
9053 <SubType>Form</SubType>
9154 </Compile>
@@ -118,41 +81,13 @@
11881 </Compile>
11982 </ItemGroup>
12083 <ItemGroup>
121- <None Include="App.config">
122- <SubType>Designer</SubType>
123- </None>
124- </ItemGroup>
125- <ItemGroup>
126- <Content Include="VMwPlayerTaskTray.ico" />
127- <None Include="VMwPlayerTaskTray_suspend.ico" />
128- <None Include="VMwPlayerTaskTray_stop.ico" />
129- <None Include="VMwPlayerTaskTray_run.ico" />
130- <None Include="VMwPlayerTaskTray_proc.ico" />
131- <None Include="VMwPlayerTaskTray_err.ico" />
84+ <None Include="App.config" />
13285 </ItemGroup>
13386 <ItemGroup>
134- <BootstrapperPackage Include=".NETFramework,Version=v4.5">
135- <Visible>False</Visible>
136- <ProductName>Microsoft .NET Framework 4.5 %28x86 および x64%29</ProductName>
137- <Install>true</Install>
138- </BootstrapperPackage>
139- <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
140- <Visible>False</Visible>
141- <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
142- <Install>false</Install>
143- </BootstrapperPackage>
144- <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
145- <Visible>False</Visible>
146- <ProductName>.NET Framework 3.5 SP1</ProductName>
147- <Install>false</Install>
148- </BootstrapperPackage>
87+ <None Include="NotifyMessage.ico" />
14988 </ItemGroup>
15089 <ItemGroup>
151- <ProjectReference Include="..\CtrlVIX\CtrlVIX.csproj">
152- <Project>{707ae0e6-ab93-4ee1-a708-bf95f91a3e30}</Project>
153- <Name>CtrlVIX</Name>
154- <EmbedInteropTypes>False</EmbedInteropTypes>
155- </ProjectReference>
90+ <None Include="NotifyMessageTray.ico" />
15691 </ItemGroup>
15792 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
15893 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Binary files /dev/null and b/NotifyMessage/NotifyMessage.ico differ
Binary files a/VMwPlayerTaskTray/VMwPlayerTaskTray_stop.ico and b/NotifyMessage/NotifyMessageTray.ico differ
--- /dev/null
+++ b/NotifyMessage/Program.cs
@@ -0,0 +1,50 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Threading.Tasks;
5+using System.Windows.Forms;
6+
7+
8+namespace NotifyMessage
9+{
10+ static class Program
11+ {
12+ // グローバル変数
13+ public static string Message = "";
14+ public enum MSGLEVEL : int // MessageLevel
15+ {
16+ INFO = 1,
17+ WARN,
18+ ERR,
19+ };
20+ public static MSGLEVEL msglevel = MSGLEVEL.INFO;
21+
22+ /// <summary>
23+ /// アプリケーションのメイン エントリ ポイントです。
24+ /// </summary>
25+ [STAThread]
26+ static void Main()
27+ {
28+ Application.EnableVisualStyles();
29+ Application.SetCompatibleTextRenderingDefault(false);
30+ // 分けて処理をして最初にフォームを表示しないようにする
31+ // Application.Run(new MainForm());
32+
33+ string[] cmds = System.Environment.GetCommandLineArgs();
34+ for (int i = 1; i < cmds.Length; i++)
35+ {
36+ if (0 <= cmds[i].IndexOf("/ERR", StringComparison.OrdinalIgnoreCase)) msglevel = MSGLEVEL.ERR;
37+ else if (0 <= cmds[i].IndexOf("/WARN", StringComparison.OrdinalIgnoreCase)) msglevel = MSGLEVEL.WARN;
38+ else if (0 <= cmds[i].IndexOf("/INFO", StringComparison.OrdinalIgnoreCase)) msglevel = MSGLEVEL.INFO;
39+ else Message = cmds[i];
40+ }
41+
42+ new MainForm();
43+
44+ if (Message != "")
45+ {
46+ //Application.Run();
47+ }
48+ }
49+ }
50+}
--- a/VMwPlayerTaskTray/Properties/AssemblyInfo.cs
+++ b/NotifyMessage/Properties/AssemblyInfo.cs
@@ -5,12 +5,12 @@ using System.Runtime.InteropServices;
55 // アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
66 // アセンブリに関連付けられている情報を変更するには、
77 // これらの属性値を変更してください。
8-[assembly: AssemblyTitle("VMwPlayerTaskTray")]
9-[assembly: AssemblyDescription("Controlling VMware Player in Tasktray.")]
8+[assembly: AssemblyTitle("NotifyMessage")]
9+[assembly: AssemblyDescription("Notifiying a message in Action center.")]
1010 [assembly: AssemblyConfiguration("")]
1111 [assembly: AssemblyCompany("")]
12-[assembly: AssemblyProduct("VMwPlayerTaskTray")]
13-[assembly: AssemblyCopyright("Copyright © 2014-2015 JeffyTS All rights reserved.")]
12+[assembly: AssemblyProduct("NotifyMessage")]
13+[assembly: AssemblyCopyright("Copyright © 2015 JeffyTS All rights reserved")]
1414 [assembly: AssemblyTrademark("")]
1515 [assembly: AssemblyCulture("")]
1616
@@ -19,18 +19,18 @@ using System.Runtime.InteropServices;
1919 // その型の ComVisible 属性を true に設定してください。
2020 [assembly: ComVisible(false)]
2121
22-// 次の GUID は、このプロジェクトが COM に公開される場合の、typelib の ID です
23-[assembly: Guid("5ce94cff-d17f-4696-99e8-ac93305eefa6")]
22+// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
23+[assembly: Guid("1bf662df-003b-43f9-9e1f-c5fa0cf8092f")]
2424
25-// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
25+// アセンブリのバージョン情報は次の 4 つの値で構成されています:
2626 //
27-// Major Version
28-// Minor Version
29-// Build Number
27+// メジャー バージョン
28+// マイナー バージョン
29+// ビルド番号
3030 // Revision
3131 //
3232 // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
3333 // 既定値にすることができます:
3434 // [assembly: AssemblyVersion("1.0.*")]
35-[assembly: AssemblyVersion("1.1.8.*")]
36-[assembly: AssemblyFileVersion("1.1.8.0")]
35+[assembly: AssemblyVersion("1.0.0.*")]
36+[assembly: AssemblyFileVersion("1.0.0.0")]
--- a/VMwPlayerTaskTray/Properties/Resources.Designer.cs
+++ b/NotifyMessage/Properties/Resources.Designer.cs
@@ -1,14 +1,14 @@
11 //------------------------------------------------------------------------------
22 // <auto-generated>
33 // このコードはツールによって生成されました。
4-// ランタイム バージョン:4.0.30319.18444
4+// ランタイム バージョン:4.0.30319.42000
55 //
66 // このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
77 // コードが再生成されるときに損失したりします。
88 // </auto-generated>
99 //------------------------------------------------------------------------------
1010
11-namespace VMwPlayerTaskTray.Properties {
11+namespace NotifyMessage.Properties {
1212 using System;
1313
1414
@@ -39,7 +39,7 @@ namespace VMwPlayerTaskTray.Properties {
3939 internal static global::System.Resources.ResourceManager ResourceManager {
4040 get {
4141 if (object.ReferenceEquals(resourceMan, null)) {
42- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VMwPlayerTaskTray.Properties.Resources", typeof(Resources).Assembly);
42+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("NotifyMessage.Properties.Resources", typeof(Resources).Assembly);
4343 resourceMan = temp;
4444 }
4545 return resourceMan;
@@ -61,60 +61,11 @@ namespace VMwPlayerTaskTray.Properties {
6161 }
6262
6363 /// <summary>
64- /// に類似しているローカライズされた文字列を検索します。
65- /// </summary>
66- internal static string VMwPlayerTaskTray {
67- get {
68- return ResourceManager.GetString("VMwPlayerTaskTray", resourceCulture);
69- }
70- }
71-
72- /// <summary>
73- /// (アイコン) に類似した型 System.Drawing.Icon のローカライズされたリソースを検索します。
74- /// </summary>
75- internal static System.Drawing.Icon VMwPlayerTaskTray_err {
76- get {
77- object obj = ResourceManager.GetObject("VMwPlayerTaskTray_err", resourceCulture);
78- return ((System.Drawing.Icon)(obj));
79- }
80- }
81-
82- /// <summary>
83- /// (アイコン) に類似した型 System.Drawing.Icon のローカライズされたリソースを検索します。
84- /// </summary>
85- internal static System.Drawing.Icon VMwPlayerTaskTray_ico {
86- get {
87- object obj = ResourceManager.GetObject("VMwPlayerTaskTray_ico", resourceCulture);
88- return ((System.Drawing.Icon)(obj));
89- }
90- }
91-
92- /// <summary>
93- /// (アイコン) に類似した型 System.Drawing.Icon のローカライズされたリソースを検索します。
94- /// </summary>
95- internal static System.Drawing.Icon VMwPlayerTaskTray_proc {
96- get {
97- object obj = ResourceManager.GetObject("VMwPlayerTaskTray_proc", resourceCulture);
98- return ((System.Drawing.Icon)(obj));
99- }
100- }
101-
102- /// <summary>
103- /// (アイコン) に類似した型 System.Drawing.Icon のローカライズされたリソースを検索します。
104- /// </summary>
105- internal static System.Drawing.Icon VMwPlayerTaskTray_run {
106- get {
107- object obj = ResourceManager.GetObject("VMwPlayerTaskTray_run", resourceCulture);
108- return ((System.Drawing.Icon)(obj));
109- }
110- }
111-
112- /// <summary>
11364 /// (アイコン) に類似した型 System.Drawing.Icon のローカライズされたリソースを検索します。
11465 /// </summary>
115- internal static System.Drawing.Icon VMwPlayerTaskTray_stop {
66+ internal static System.Drawing.Icon NotifyMessage {
11667 get {
117- object obj = ResourceManager.GetObject("VMwPlayerTaskTray_stop", resourceCulture);
68+ object obj = ResourceManager.GetObject("NotifyMessage", resourceCulture);
11869 return ((System.Drawing.Icon)(obj));
11970 }
12071 }
@@ -122,9 +73,9 @@ namespace VMwPlayerTaskTray.Properties {
12273 /// <summary>
12374 /// (アイコン) に類似した型 System.Drawing.Icon のローカライズされたリソースを検索します。
12475 /// </summary>
125- internal static System.Drawing.Icon VMwPlayerTaskTray_suspend {
76+ internal static System.Drawing.Icon NotifyMessageTray {
12677 get {
127- object obj = ResourceManager.GetObject("VMwPlayerTaskTray_suspend", resourceCulture);
78+ object obj = ResourceManager.GetObject("NotifyMessageTray", resourceCulture);
12879 return ((System.Drawing.Icon)(obj));
12980 }
13081 }
--- a/VMwPlayerTaskTray/MainForm.resx
+++ b/NotifyMessage/Properties/Resources.resx
@@ -117,14 +117,11 @@
117117 <resheader name="writer">
118118 <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119 </resheader>
120- <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
121- <data name="notifyIcon_MainForm.TrayLocation" type="System.Drawing.Point, System.Drawing">
122- <value>168, 17</value>
120+ <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121+ <data name="NotifyMessage" type="System.Resources.ResXFileRef, System.Windows.Forms">
122+ <value>..\NotifyMessage.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
123123 </data>
124- <data name="contextMenuStrip_MainForm.TrayLocation" type="System.Drawing.Point, System.Drawing">
125- <value>347, 17</value>
126- </data>
127- <data name="timer_MainForm.TrayLocation" type="System.Drawing.Point, System.Drawing">
128- <value>17, 17</value>
124+ <data name="NotifyMessageTray" type="System.Resources.ResXFileRef, System.Windows.Forms">
125+ <value>..\NotifyMessageTray.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
129126 </data>
130127 </root>
\ No newline at end of file
--- a/VMwPlayerTaskTray/Properties/Settings.Designer.cs
+++ b/NotifyMessage/Properties/Settings.Designer.cs
@@ -1,14 +1,14 @@
11 //------------------------------------------------------------------------------
22 // <auto-generated>
33 // This code was generated by a tool.
4-// Runtime Version:4.0.30319.18444
4+// Runtime Version:4.0.30319.42000
55 //
66 // Changes to this file may cause incorrect behavior and will be lost if
77 // the code is regenerated.
88 // </auto-generated>
99 //------------------------------------------------------------------------------
1010
11-namespace VMwPlayerTaskTray.Properties
11+namespace NotifyMessage.Properties
1212 {
1313
1414
--- a/VMwPlayerTaskTray/MainForm.Designer.cs
+++ /dev/null
@@ -1,243 +0,0 @@
1-namespace VMwPlayerTaskTray
2-{
3- partial class MainForm
4- {
5- /// <summary>
6- /// 必要なデザイナー変数です。
7- /// </summary>
8- private System.ComponentModel.IContainer components = null;
9-
10- /// <summary>
11- /// 使用中のリソースをすべてクリーンアップします。
12- /// </summary>
13- /// <param name="disposing">マネージ リソースが破棄される場合 true、破棄されない場合は false です。</param>
14- protected override void Dispose(bool disposing)
15- {
16- if (disposing && (components != null))
17- {
18- components.Dispose();
19- }
20- base.Dispose(disposing);
21- }
22-
23- #region Windows フォーム デザイナーで生成されたコード
24-
25- /// <summary>
26- /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
27- /// コード エディターで変更しないでください。
28- /// </summary>
29- private void InitializeComponent()
30- {
31- this.components = new System.ComponentModel.Container();
32- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
33- this.notifyIcon_MainForm = new System.Windows.Forms.NotifyIcon(this.components);
34- this.contextMenuStrip_MainForm = new System.Windows.Forms.ContextMenuStrip(this.components);
35- this.ToolStripMenuItem_VMwPlayerTaskTray = new System.Windows.Forms.ToolStripMenuItem();
36- this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
37- this.ToolStripMenuItem_GoGUI = new System.Windows.Forms.ToolStripMenuItem();
38- this.ToolStripMenuItem_GoNoGUI = new System.Windows.Forms.ToolStripMenuItem();
39- this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
40- this.ToolStripMenuItem_GoSuspend = new System.Windows.Forms.ToolStripMenuItem();
41- this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
42- this.ToolStripMenuItem_OtherCommand = new System.Windows.Forms.ToolStripMenuItem();
43- this.ToolStripMenuItem_ACPIReset = new System.Windows.Forms.ToolStripMenuItem();
44- this.ToolStripMenuItem_ACPIPowerOff = new System.Windows.Forms.ToolStripMenuItem();
45- this.toolStripSeparator4 = new System.Windows.Forms.ToolStripSeparator();
46- this.ToolStripMenuItem_Reset = new System.Windows.Forms.ToolStripMenuItem();
47- this.ToolStripMenuItem_PowerOff = new System.Windows.Forms.ToolStripMenuItem();
48- this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
49- this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
50- this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator();
51- this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
52- this.timer_MainForm = new System.Windows.Forms.Timer(this.components);
53- this.contextMenuStrip_MainForm.SuspendLayout();
54- this.SuspendLayout();
55- //
56- // notifyIcon_MainForm
57- //
58- this.notifyIcon_MainForm.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
59- this.notifyIcon_MainForm.BalloonTipText = "VMwarePlayerTaskTray";
60- this.notifyIcon_MainForm.BalloonTipTitle = "VMwarePlayerTaskTray";
61- this.notifyIcon_MainForm.ContextMenuStrip = this.contextMenuStrip_MainForm;
62- this.notifyIcon_MainForm.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon_MainForm.Icon")));
63- this.notifyIcon_MainForm.Text = "VMwarePlayerTaskTray";
64- this.notifyIcon_MainForm.Visible = true;
65- this.notifyIcon_MainForm.MouseUp += new System.Windows.Forms.MouseEventHandler(this.notifyIcon_MainForm_MouseUp);
66- //
67- // contextMenuStrip_MainForm
68- //
69- this.contextMenuStrip_MainForm.BackColor = System.Drawing.SystemColors.Control;
70- this.contextMenuStrip_MainForm.Font = new System.Drawing.Font("メイリオ", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
71- this.contextMenuStrip_MainForm.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
72- this.ToolStripMenuItem_VMwPlayerTaskTray,
73- this.toolStripSeparator3,
74- this.ToolStripMenuItem_GoGUI,
75- this.ToolStripMenuItem_GoNoGUI,
76- this.toolStripSeparator2,
77- this.ToolStripMenuItem_GoSuspend,
78- this.toolStripSeparator1,
79- this.ToolStripMenuItem_OtherCommand,
80- this.toolStripSeparator6,
81- this.aboutToolStripMenuItem,
82- this.toolStripSeparator7,
83- this.exitToolStripMenuItem});
84- this.contextMenuStrip_MainForm.Name = "contextMenuStrip1";
85- this.contextMenuStrip_MainForm.ShowImageMargin = false;
86- this.contextMenuStrip_MainForm.Size = new System.Drawing.Size(190, 202);
87- //
88- // ToolStripMenuItem_VMwPlayerTaskTray
89- //
90- this.ToolStripMenuItem_VMwPlayerTaskTray.Font = new System.Drawing.Font("メイリオ", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(128)));
91- this.ToolStripMenuItem_VMwPlayerTaskTray.Name = "ToolStripMenuItem_VMwPlayerTaskTray";
92- this.ToolStripMenuItem_VMwPlayerTaskTray.Size = new System.Drawing.Size(189, 24);
93- this.ToolStripMenuItem_VMwPlayerTaskTray.Text = "VMwPlayerTaskTray";
94- this.ToolStripMenuItem_VMwPlayerTaskTray.Click += new System.EventHandler(this.ToolStripMenuItem_VMwPlayerTaskTray_Click);
95- //
96- // toolStripSeparator3
97- //
98- this.toolStripSeparator3.Name = "toolStripSeparator3";
99- this.toolStripSeparator3.Size = new System.Drawing.Size(186, 6);
100- //
101- // ToolStripMenuItem_GoGUI
102- //
103- this.ToolStripMenuItem_GoGUI.Name = "ToolStripMenuItem_GoGUI";
104- this.ToolStripMenuItem_GoGUI.Size = new System.Drawing.Size(189, 24);
105- this.ToolStripMenuItem_GoGUI.Text = "Go GUI";
106- this.ToolStripMenuItem_GoGUI.Click += new System.EventHandler(this.ToolStripMenuItem_GoGUI_Click);
107- //
108- // ToolStripMenuItem_GoNoGUI
109- //
110- this.ToolStripMenuItem_GoNoGUI.Name = "ToolStripMenuItem_GoNoGUI";
111- this.ToolStripMenuItem_GoNoGUI.Size = new System.Drawing.Size(189, 24);
112- this.ToolStripMenuItem_GoNoGUI.Text = "Go NoGUI";
113- this.ToolStripMenuItem_GoNoGUI.Click += new System.EventHandler(this.ToolStripMenuItem_GoNoGUI_Click);
114- //
115- // toolStripSeparator2
116- //
117- this.toolStripSeparator2.Name = "toolStripSeparator2";
118- this.toolStripSeparator2.Size = new System.Drawing.Size(186, 6);
119- //
120- // ToolStripMenuItem_GoSuspend
121- //
122- this.ToolStripMenuItem_GoSuspend.Name = "ToolStripMenuItem_GoSuspend";
123- this.ToolStripMenuItem_GoSuspend.Size = new System.Drawing.Size(189, 24);
124- this.ToolStripMenuItem_GoSuspend.Text = "Go Suspend";
125- this.ToolStripMenuItem_GoSuspend.Click += new System.EventHandler(this.ToolStripMenuItem_GoSuspend_Click);
126- //
127- // toolStripSeparator1
128- //
129- this.toolStripSeparator1.Name = "toolStripSeparator1";
130- this.toolStripSeparator1.Size = new System.Drawing.Size(186, 6);
131- //
132- // ToolStripMenuItem_OtherCommand
133- //
134- this.ToolStripMenuItem_OtherCommand.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
135- this.ToolStripMenuItem_ACPIReset,
136- this.ToolStripMenuItem_ACPIPowerOff,
137- this.toolStripSeparator4,
138- this.ToolStripMenuItem_Reset,
139- this.ToolStripMenuItem_PowerOff});
140- this.ToolStripMenuItem_OtherCommand.Name = "ToolStripMenuItem_OtherCommand";
141- this.ToolStripMenuItem_OtherCommand.Size = new System.Drawing.Size(189, 24);
142- this.ToolStripMenuItem_OtherCommand.Text = "Other Command";
143- this.ToolStripMenuItem_OtherCommand.DropDownOpening += new System.EventHandler(this.ToolStripMenuItem_OtherCommand_DropDownOpening);
144- //
145- // ToolStripMenuItem_ACPIReset
146- //
147- this.ToolStripMenuItem_ACPIReset.Name = "ToolStripMenuItem_ACPIReset";
148- this.ToolStripMenuItem_ACPIReset.Size = new System.Drawing.Size(181, 24);
149- this.ToolStripMenuItem_ACPIReset.Text = "ACPI Reset";
150- this.ToolStripMenuItem_ACPIReset.Click += new System.EventHandler(this.ToolStripMenuItem_ACPIReset_Click);
151- //
152- // ToolStripMenuItem_ACPIPowerOff
153- //
154- this.ToolStripMenuItem_ACPIPowerOff.Name = "ToolStripMenuItem_ACPIPowerOff";
155- this.ToolStripMenuItem_ACPIPowerOff.Size = new System.Drawing.Size(181, 24);
156- this.ToolStripMenuItem_ACPIPowerOff.Text = "ACPI Power OFF";
157- this.ToolStripMenuItem_ACPIPowerOff.Click += new System.EventHandler(this.ToolStripMenuItem_ACPIPowerOff_Click);
158- //
159- // toolStripSeparator4
160- //
161- this.toolStripSeparator4.Name = "toolStripSeparator4";
162- this.toolStripSeparator4.Size = new System.Drawing.Size(178, 6);
163- //
164- // ToolStripMenuItem_Reset
165- //
166- this.ToolStripMenuItem_Reset.Name = "ToolStripMenuItem_Reset";
167- this.ToolStripMenuItem_Reset.Size = new System.Drawing.Size(181, 24);
168- this.ToolStripMenuItem_Reset.Text = "Reset...";
169- this.ToolStripMenuItem_Reset.Click += new System.EventHandler(this.ToolStripMenuItem_Reset_Click);
170- //
171- // ToolStripMenuItem_PowerOff
172- //
173- this.ToolStripMenuItem_PowerOff.Name = "ToolStripMenuItem_PowerOff";
174- this.ToolStripMenuItem_PowerOff.Size = new System.Drawing.Size(181, 24);
175- this.ToolStripMenuItem_PowerOff.Text = "Power OFF...";
176- this.ToolStripMenuItem_PowerOff.Click += new System.EventHandler(this.ToolStripMenuItem_PowerOff_Click);
177- //
178- // toolStripSeparator6
179- //
180- this.toolStripSeparator6.Name = "toolStripSeparator6";
181- this.toolStripSeparator6.Size = new System.Drawing.Size(186, 6);
182- //
183- // aboutToolStripMenuItem
184- //
185- this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
186- this.aboutToolStripMenuItem.Size = new System.Drawing.Size(189, 24);
187- this.aboutToolStripMenuItem.Text = "About...";
188- this.aboutToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_About_Click);
189- //
190- // toolStripSeparator7
191- //
192- this.toolStripSeparator7.Name = "toolStripSeparator7";
193- this.toolStripSeparator7.Size = new System.Drawing.Size(186, 6);
194- //
195- // exitToolStripMenuItem
196- //
197- this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
198- this.exitToolStripMenuItem.Size = new System.Drawing.Size(189, 24);
199- this.exitToolStripMenuItem.Text = "Exit";
200- this.exitToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Exit_Click);
201- //
202- // timer_MainForm
203- //
204- this.timer_MainForm.Tick += new System.EventHandler(this.timer_MainForm_Tick);
205- //
206- // MainForm
207- //
208- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
209- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
210- this.ClientSize = new System.Drawing.Size(293, 121);
211- this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
212- this.Name = "MainForm";
213- this.Text = "VMwarePlayerTaskTray";
214- this.contextMenuStrip_MainForm.ResumeLayout(false);
215- this.ResumeLayout(false);
216-
217- }
218-
219- #endregion
220-
221- private System.Windows.Forms.NotifyIcon notifyIcon_MainForm;
222- private System.Windows.Forms.ContextMenuStrip contextMenuStrip_MainForm;
223- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_GoGUI;
224- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_GoNoGUI;
225- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_GoSuspend;
226- private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
227- private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
228- private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
229- private System.Windows.Forms.Timer timer_MainForm;
230- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_VMwPlayerTaskTray;
231- private System.Windows.Forms.ToolStripSeparator toolStripSeparator3;
232- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_OtherCommand;
233- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_ACPIReset;
234- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_ACPIPowerOff;
235- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_Reset;
236- private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem_PowerOff;
237- private System.Windows.Forms.ToolStripSeparator toolStripSeparator6;
238- private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
239- private System.Windows.Forms.ToolStripSeparator toolStripSeparator7;
240- private System.Windows.Forms.ToolStripSeparator toolStripSeparator4;
241- }
242-}
243-
--- a/VMwPlayerTaskTray/MainForm.cs
+++ /dev/null
@@ -1,227 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.ComponentModel;
4-using System.Data;
5-using System.Drawing;
6-using System.Linq;
7-using System.Text;
8-using System.Threading.Tasks;
9-using System.Windows.Forms;
10-
11-using System.Reflection; // Add
12-using System.Management; // Add
13-using System.Diagnostics; // Add
14-using System.IO; // Add
15-
16-namespace VMwPlayerTaskTray
17-{
18- public partial class MainForm : Form
19- {
20- // This Program Name
21- private const string PROGRAM_NAME = "VMwPlayerTaskTray";
22-
23- // Messages
24- private const string MSG_ARG_ERR = "Gust OS's vmx file not be in argument.\r\n" +
25- "\r\n";
26- private const string MSG_USAGE = " Usage: \r\n" +
27- " " + PROGRAM_NAME + ".exe [opt] \"FullPath.vmx\"\r\n" +
28- "\r\n" +
29- " Option:\r\n" +
30- " /gui | /nogui | (none)\r\n" +
31- " /pos num_left num_top | (none)";
32- private const string MSG_RUN_DUP = PROGRAM_NAME + " has been already running with \r\n" +
33- "same guest OS.\r\n" +
34- "\r\n" +
35- "Extiting...";
36-
37- // クラス内のグローバル変数
38- private string vmxFilePath = "";
39- private VMSTATE vmState = VMSTATE.UNDEFINED;
40-
41- public MainForm()
42- {
43- string vmxName;
44-
45- // Messageはここで出さないと終了処理がうまくいかない(プロセスが残る)
46- if (Program.vmxFilePath == "")
47- {
48- MessageBox.Show(MSG_ARG_ERR + MSG_USAGE, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
49- Program.vmxFilePath = ""; // Program.vmxFilePathを消してしまう(flag代わり)
50- }
51- else if (Program.vmxFilePath != "") // vmxFilePathが指定されていないときは初期化せず終了
52- {
53- vmxFilePath = Program.vmxFilePath; // Mainで設定されたvmxFilePathをコピー
54- vmxName = Path.GetFileNameWithoutExtension(vmxFilePath); // vmx 名を作成
55-
56- if (CountProcess(PROGRAM_NAME, vmxName) > 1) // 二重起動のチェック
57- {
58- MessageBox.Show(MSG_RUN_DUP, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
59- Program.vmxFilePath = ""; // Program.vmxFilePathを消してしまう(flag代わり)
60- return;
61- }
62- InitializeComponent();
63- this.ToolStripMenuItem_VMwPlayerTaskTray.Text = vmxName; // メニューの1行目のタイトルセット
64- this.timer_MainForm.Interval = 3000; // Timer 時間セット
65- this.timer_MainForm.Enabled = false; // Timerを無効にする
66- vmState = VMSTATE.UNDEFINED; // vmState をリセットする
67- ChangeMenuItem(vmxFilePath); // VMwareの動作状態をチェックしMenuItemの表示を切り替える
68- if (vmState == VMSTATE.ERROR)
69- {
70- Program.vmxFilePath = ""; // Program.vmxFilePathを消してしまう(flag代わり)
71- return;
72- }
73- // start option がついていたらVMwareを起動する
74- if (vmState != VMSTATE.NO_VMXFILE)
75- {
76- if (Program.startMode == "/gui")
77- {
78- VMControl(VMCTRL.GO_GUI);
79- }
80- else if (Program.startMode == "/nogui")
81- {
82- VMControl(VMCTRL.GO_NOGUI);
83- }
84- else
85- {
86- this.timer_MainForm.Enabled = true; // Timerを有効にする
87- }
88- }
89- else
90- {
91- this.timer_MainForm.Enabled = true; // Timerを有効にする
92- }
93- // うるさいのでやめるthis.notifyIcon1.ShowBalloonTip(500); // バルーンTip表示
94- }
95- }
96-
97- private void timer_MainForm_Tick(object sender, EventArgs e)
98- {
99- this.timer_MainForm.Enabled = false; // Timerを無効にする
100-#if DEBUG
101- //Debug.WriteLine("Timer Thread : Start");
102-#endif
103- ChangeMenuItem(vmxFilePath); // VMwareの動作状態をチェックしMenuItemの表示を切り替える
104- if (vmState == VMSTATE.ERROR)
105- {
106- // Exit
107- this.notifyIcon_MainForm.Visible = false; // タスクトレイからアイコンを取り除く
108- Application.Exit(); // アプリケーション終了
109- }
110-#if DEBUG
111- //Debug.WriteLine("Timer Thread : Finish");
112-#endif
113- this.timer_MainForm.Enabled = true; // Timerを有効にする
114- }
115-
116- private void notifyIcon_MainForm_MouseUp(object sender, MouseEventArgs e)
117- {
118- switch (e.Button)
119- {
120- case MouseButtons.Left:
121- // 何もしない
122- break;
123- case MouseButtons.Middle:
124- // 何もしない
125- break;
126- case MouseButtons.Right:
127- // 何もしない
128- break;
129- }
130- // どのボタンでもメニューを出す
131- //this.timer1.Enabled = false; // Timerを無効にする
132- this.notifyIcon_MainForm.ContextMenuStrip = this.contextMenuStrip_MainForm;
133- MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic);
134- mi.Invoke(this.notifyIcon_MainForm, null);
135- this.notifyIcon_MainForm.ContextMenuStrip = null;
136- this.contextMenuStrip_MainForm.Show(this, PointToClient(Cursor.Position));
137- //this.timer1.Enabled = true; // Timerを有効にする
138- }
139-
140- private void ToolStripMenuItem_VMwPlayerTaskTray_Click(object sender, EventArgs e)
141- {
142- // this.timer1.Enabled = false; // Timerを無効にする
143- vmState = VMSTATE.UNDEFINED; // vmState をリセットする
144- ChangeMenuItem(vmxFilePath); // VMwareの動作状態をチェックしMenuItemの表示を切り替える
145- if (vmState == VMSTATE.ERROR)
146- {
147- // Exit
148- this.notifyIcon_MainForm.Visible = false; // タスクトレイからアイコンを取り除く
149- Application.Exit(); // アプリケーション終了
150- }
151- // this.timer1.Enabled = true; // Timerを有効にする
152- }
153-
154- private void ToolStripMenuItem_GoGUI_Click(object sender, EventArgs e)
155- {
156- VMControl(VMCTRL.GO_GUI);
157- }
158-
159- private void ToolStripMenuItem_GoNoGUI_Click(object sender, EventArgs e)
160- {
161- VMControl(VMCTRL.GO_NOGUI);
162- }
163-
164- private void ToolStripMenuItem_GoSuspend_Click(object sender, EventArgs e)
165- {
166- VMControl(VMCTRL.GO_SUSPEND);
167- }
168-
169- private void ToolStripMenuItem_OtherCommand_DropDownOpening(object sender, EventArgs e)
170- {
171- // Check & Set Items Enable/Disable
172- if (isToolsRunning(vmxFilePath))
173- {
174- ToolStripMenuItem_ACPIReset.Enabled = true;
175- ToolStripMenuItem_ACPIPowerOff.Enabled = true;
176- }
177- else
178- {
179- ToolStripMenuItem_ACPIReset.Enabled = false;
180- ToolStripMenuItem_ACPIPowerOff.Enabled = false;
181- }
182- ToolStripMenuItem_Reset.Enabled = true;
183- ToolStripMenuItem_PowerOff.Enabled = true;
184- }
185-
186- private void ToolStripMenuItem_ACPIReset_Click(object sender, EventArgs e)
187- {
188- VMControl(VMCTRL.GO_ACPI_RESET);
189- }
190-
191- private void ToolStripMenuItem_ACPIPowerOff_Click(object sender, EventArgs e)
192- {
193- VMControl(VMCTRL.GO_ACPI_POWER_OFF);
194- }
195-
196- private void ToolStripMenuItem_Reset_Click(object sender, EventArgs e)
197- {
198- // open dialog
199- if (confirmDialog())
200- {
201- VMControl(VMCTRL.GO_RESET);
202- }
203- }
204-
205- private void ToolStripMenuItem_PowerOff_Click(object sender, EventArgs e)
206- {
207- // open dialog
208- if (confirmDialog())
209- {
210- VMControl(VMCTRL.GO_POWER_OFF);
211- }
212- }
213-
214- private void ToolStripMenuItem_About_Click(object sender, EventArgs e)
215- {
216- // About dialog
217- AboutDialog();
218- }
219-
220- private void ToolStripMenuItem_Exit_Click(object sender, EventArgs e)
221- {
222- // Exit
223- this.notifyIcon_MainForm.Visible = false; // タスクトレイからアイコンを取り除く
224- Application.Exit(); // アプリケーション終了
225- }
226- }
227-}
--- a/VMwPlayerTaskTray/MainFormSub.cs
+++ /dev/null
@@ -1,717 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-using System.Threading.Tasks;
6-using System.Windows.Forms;
7-
8-using CtrlVix; // Add
9-using System.Reflection; // Add
10-using System.Management; // Add
11-using System.Diagnostics; // Add
12-using System.IO; // Add
13-using System.Runtime.InteropServices; // Add DLL Import
14-
15-
16-namespace VMwPlayerTaskTray
17-{
18- public partial class MainForm
19- {
20- // Messages
21- private const string MSG_ABOUT = "Thanks to VMware,Inc and Microsoft Corporation.\r\n" +
22- "\r\n" +
23- "This program has been developed on\r\n" +
24- " VMware Workstation Player 12.0.0 and VMware VIX 1.15.0\r\n" + // Ver.12
25- " Visual Studio Community 2015\r\n" +
26- " Windows10 Professional 64bit.\r\n" +
27- "\r\n" +
28- MSG_USAGE;
29- private const string MSG_VIX_ERR = "A fatal error has occured inside VIX.\r\n" +
30- "Exiting " + PROGRAM_NAME + "...";
31- private const string MSG_CONFIRM = "Are you sure?\r\n" +
32- "It might be cause of crushing your guest OS...";
33- private const string MSG_BALN_WARN = "GUI/NoGUI couldn't be determined when guest OS started by \"VMware Player\". " +
34- "It might be cause of loosing control.";
35- private const string MSG_BALN_NO_VMX_FILE = ".vmx\" file not found. Check your VM path.";
36-
37- // クラス内のグローバル変数
38- private enum VMSTATE : int // ChangeMenuItem()
39- {
40- UNDEFINED = 0,
41- POWERED_ON,
42- PROCESSING,
43- POWERED_OFF,
44- NO_VMXFILE,
45- ERROR = 0xffff
46- };
47- private enum VMCTRL : int // VMControl()
48- {
49- GO_GUI = 1,
50- GO_NOGUI,
51- GO_SUSPEND,
52- GO_ACPI_RESET,
53- GO_ACPI_POWER_OFF,
54- GO_RESET,
55- GO_POWER_OFF
56- };
57- private enum MENU_MODE : int // SetMenuItem()
58- {
59- UNDEFINED = 0,
60- RUNNING_GUI,
61- RUNNING_NOGUI,
62- PROCESSING,
63- SUSPENDED,
64- POWERED_OFF,
65- CANNOT_DEFINE_RUNNING_MODE,
66- NO_VMXFILE,
67- //NOT_RUNNING_VMTOOLS,
68- ERROR = 0xffff
69- };
70- private bool inprocess = false; // 非同期処理中かどうかのフラグ
71-
72- private async void VMControl(VMCTRL mode)
73- {
74- bool ret = true; ;
75-
76- this.timer_MainForm.Enabled = false; // Timerを無効にする
77- SetMenuItem(MENU_MODE.PROCESSING); // MenuItemの表示を処理中にセット
78- inprocess = true; // 非同期処理中フラグ
79-#if DEBUG
80- Debug.WriteLine("Start VMControl Thread");
81-#endif
82- ret = await Task.Run(() =>
83- {
84- return subVMControl(mode); // VM Control
85- });
86-#if DEBUG
87- Debug.WriteLine("Finish VMControl Thread");
88-#endif
89- inprocess = false; // 非同期処理中フラグ
90- if (!ret)
91- {
92- SetMenuItem(MENU_MODE.ERROR); // Exit
93- this.notifyIcon_MainForm.Visible = false; // タスクトレイからアイコンを取り除く
94- Application.Exit(); // アプリケーション終了
95- return;
96- }
97- vmState = VMSTATE.UNDEFINED; // vmState をリセットする
98- ChangeMenuItem(vmxFilePath); // VMwareの動作状態をチェックしMenuItemの表示を切り替える
99- if (vmState == VMSTATE.ERROR)
100- {
101- // Exit
102- this.notifyIcon_MainForm.Visible = false; // タスクトレイからアイコンを取り除く
103- Application.Exit(); // アプリケーション終了
104- }
105- this.timer_MainForm.Enabled = true; // Timerを有効にする
106- }
107-
108- private bool subVMControl(VMCTRL mode)
109- {
110- Constants.VMSTATE state;
111- Constants.POWER_OFF_MODE pwOff;
112- CtrlVIX Vix = new CtrlVIX();
113-
114- switch (mode)
115- {
116- case VMCTRL.GO_GUI:
117- if ((vmState == VMSTATE.POWERED_ON) && (Vix.CheckRunningMode(vmxFilePath) == Constants.RUNNING_MODE.NOGUI))
118- {
119- // Go to Suspend mode
120- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.SUSPEND)) return false;
121- //@@@for (int i = 0; i < 10; i++)
122- {
123- System.Threading.Thread.Sleep(3000);
124- if (((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_OFF)
125- && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath))
126- != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED))
127- {
128- if (state == CtrlVix.Constants.VMSTATE.ERROR) return false;
129- if (pwOff == CtrlVix.Constants.POWER_OFF_MODE.ERROR) return false;
130- }
131- else
132- {
133- //@@@break;
134- }
135- }
136- }
137- // Go to GUI mode
138- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.POWER_ON_GUI)) return false;
139- break;
140- case VMCTRL.GO_NOGUI:
141- if ((vmState == VMSTATE.POWERED_ON) && (Vix.CheckRunningMode(vmxFilePath) == Constants.RUNNING_MODE.GUI))
142- {
143- // get & save current window pos
144- getPlayerWindowPos(out Program.moveWindow_left, out Program.moveWindow_top);
145-
146- // Go to Suspend mode
147- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.SUSPEND)) return false;
148- //@@@for (int i = 0; i < 10; i++)
149- {
150- System.Threading.Thread.Sleep(3000);
151- if (((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_OFF)
152- && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath))
153- != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED))
154- {
155- if (state == CtrlVix.Constants.VMSTATE.ERROR) return false;
156- if (pwOff == CtrlVix.Constants.POWER_OFF_MODE.ERROR) return false;
157- }
158- else
159- {
160- //@@@break;
161- }
162- }
163- }
164- // Go to No GUI mode
165- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.POWER_ON_NOGUI)) return false;
166- break;
167- case VMCTRL.GO_SUSPEND:
168- if ((vmState == VMSTATE.POWERED_ON) && (Vix.CheckRunningMode(vmxFilePath) == Constants.RUNNING_MODE.GUI))
169- {
170- // get & save current window pos
171- getPlayerWindowPos(out Program.moveWindow_left, out Program.moveWindow_top);
172- }
173- // Go to Suspend mode
174- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.SUSPEND)) return false;
175- break;
176- case VMCTRL.GO_ACPI_RESET:
177- // ACPI reset
178- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.ACPI_RESET)) return false;
179- break;
180- case VMCTRL.GO_ACPI_POWER_OFF:
181- if ((vmState == VMSTATE.POWERED_ON) && (Vix.CheckRunningMode(vmxFilePath) == Constants.RUNNING_MODE.GUI))
182- {
183- // get & save current window pos
184- getPlayerWindowPos(out Program.moveWindow_left, out Program.moveWindow_top);
185- }
186- // ACPI shutdown
187- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.ACPI_POWER_OFF)) return false;
188- break;
189- case VMCTRL.GO_RESET:
190- if ((vmState == VMSTATE.POWERED_ON) && (Vix.CheckRunningMode(vmxFilePath) == Constants.RUNNING_MODE.GUI))
191- {
192- // get & save current window pos
193- getPlayerWindowPos(out Program.moveWindow_left, out Program.moveWindow_top);
194- }
195- // Harware reset
196- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.HW_RESET)) return false;
197- break;
198- case VMCTRL.GO_POWER_OFF:
199- // Harware shutdown
200- if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.HW_POWER_OFF)) return false;
201- break;
202- }
203- switch (mode)
204- {
205- case VMCTRL.GO_GUI:
206- case VMCTRL.GO_NOGUI:
207- //@@@for(int i = 0; i < 10; i++)
208- {
209- System.Threading.Thread.Sleep(3000);
210- if ((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_ON)
211- {
212- if (state == CtrlVix.Constants.VMSTATE.ERROR) return false;
213- }
214- else
215- {
216- //@@@break;
217- }
218- }
219- if (mode == VMCTRL.GO_GUI && Program.moveWindow == true) // GO_GUIの時だけPlayer Windowを移動する
220- {
221- movePlayerWindow(Program.moveWindow_left, Program.moveWindow_top); // Player Windowを移動する
222- }
223- break;
224- case VMCTRL.GO_ACPI_RESET:
225- case VMCTRL.GO_RESET:
226- System.Threading.Thread.Sleep(3000);
227- break;
228- case VMCTRL.GO_SUSPEND:
229- //@@@for (int i = 0; i < 10; i++)
230- {
231- System.Threading.Thread.Sleep(3000);
232- if (((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_OFF)
233- && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath))
234- != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED))
235- {
236- if (state == CtrlVix.Constants.VMSTATE.ERROR) return false;
237- if (pwOff == CtrlVix.Constants.POWER_OFF_MODE.ERROR) return false;
238- }
239- else
240- {
241- //@@@break;
242- }
243- }
244- break;
245- case VMCTRL.GO_ACPI_POWER_OFF:
246- case VMCTRL.GO_POWER_OFF:
247- //@@@for (int i = 0; i < 10; i++)
248- {
249- System.Threading.Thread.Sleep(3000);
250- if ((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_OFF)
251- {
252- if (state == CtrlVix.Constants.VMSTATE.ERROR) return false;
253- }
254- else
255- {
256- //@@@break;
257- }
258- }
259- break;
260- }
261- return true;
262- }
263-
264- private bool isToolsRunning(string vmxFilePath)
265- {
266- CtrlVIX Vix = new CtrlVIX();
267- if (Vix.CheckToolsRunning(vmxFilePath) == CtrlVix.Constants.TOOLS_RUNNING.RUNNING)
268- {
269- return true;
270- }
271- return false;
272- }
273-
274- private void ChangeMenuItem(string vmxFilePath)
275- {
276- VMSTATE oldVMstate;
277- CtrlVIX Vix = new CtrlVIX();
278-
279- if (inprocess) return; // 非同期処理中は処理しない
280- oldVMstate = vmState; // vmStateを保存
281-
282- if (File.Exists(vmxFilePath)) // vmxファイルがあるかチェック
283- {
284- switch (Vix.GetVMState(vmxFilePath)) // VMwareの動作状態をチェックしMenuItemの表示を切り替える
285- {
286- case CtrlVix.Constants.VMSTATE.POWERED_ON:
287- vmState = VMSTATE.POWERED_ON;
288- break;
289- case CtrlVix.Constants.VMSTATE.POWERED_OFF:
290- vmState = VMSTATE.POWERED_OFF;
291- break;
292- case CtrlVix.Constants.VMSTATE.PROCESSING:
293- vmState = VMSTATE.PROCESSING;
294- break;
295- case CtrlVix.Constants.VMSTATE.ERROR:
296- vmState = VMSTATE.ERROR;
297- SetMenuItem(MENU_MODE.ERROR);
298- return; // errorの時は戻る
299- }
300- }
301- else
302- {
303- vmState = VMSTATE.NO_VMXFILE;
304- }
305- if (oldVMstate != VMSTATE.UNDEFINED)
306- {
307- // oldVMstateがUNDEFINEDではないとき
308- if (oldVMstate == vmState)
309- {
310- // VMstateとoldVMstateの状態が同じであれば処理をパスする
311- return;
312- }
313- }
314- if (vmState == VMSTATE.PROCESSING)
315- {
316-#if DEBUG
317- Debug.WriteLine("PROCESSING");
318-#endif
319- SetMenuItem(MENU_MODE.PROCESSING);
320- }
321- else if (vmState == VMSTATE.POWERED_ON)
322- {
323- switch (Vix.CheckRunningMode(vmxFilePath))
324- {
325- case CtrlVix.Constants.RUNNING_MODE.GUI:
326- // GUI mode
327- SetMenuItem(MENU_MODE.RUNNING_GUI);
328-#if DEBUG
329- Debug.WriteLine("RUNNING_GUI");
330-#endif
331- break;
332- case CtrlVix.Constants.RUNNING_MODE.NOGUI:
333- // No GUI mode
334- SetMenuItem(MENU_MODE.RUNNING_NOGUI);
335-#if DEBUG
336- Debug.WriteLine("RUNNING_NOGUI");
337-#endif
338- break;
339- case CtrlVix.Constants.RUNNING_MODE.CANNOT_DETERMINE:
340- // Guest OS started by VMware Player - can't determine GUI/NGUI
341- SetMenuItem(MENU_MODE.CANNOT_DEFINE_RUNNING_MODE);
342-#if DEBUG
343- Debug.WriteLine("CANNOT_DEFINE_RUNNING_MODE");
344-#endif
345- break;
346- }
347- }
348- else if (vmState == VMSTATE.NO_VMXFILE)
349- {
350- SetMenuItem(MENU_MODE.NO_VMXFILE);
351-#if DEBUG
352- Debug.WriteLine("NO_VMXFILE");
353-#endif
354- }
355- else
356- {
357- switch (Vix.CheckPowerOffMode(vmxFilePath))
358- {
359- case Constants.POWER_OFF_MODE.SUSPENDED:
360- // Suspended
361- SetMenuItem(MENU_MODE.SUSPENDED);
362-#if DEBUG
363- Debug.WriteLine("SUSPENDED");
364-#endif
365- break;
366- case Constants.POWER_OFF_MODE.POWERED_OFF:
367- // Powered OFF
368- SetMenuItem(MENU_MODE.POWERED_OFF);
369-#if DEBUG
370- Debug.WriteLine("POWERED_OFF");
371-#endif
372- break;
373- case Constants.POWER_OFF_MODE.ERROR:
374- SetMenuItem(MENU_MODE.ERROR);
375- break;
376- }
377- }
378- }
379-
380- private void SetMenuItem(MENU_MODE mode)
381- {
382- string vmxName = Path.GetFileNameWithoutExtension(vmxFilePath); // vmx 名を作成
383-
384- aboutToolStripMenuItem.Enabled = true; // Aboutは常に表示
385- exitToolStripMenuItem.Enabled = true; // Exitは常に表示
386- switch (mode)
387- {
388- case MENU_MODE.RUNNING_GUI:
389- ToolStripMenuItem_GoGUI.Enabled = false;
390- ToolStripMenuItem_GoNoGUI.Enabled = true;
391- ToolStripMenuItem_GoSuspend.Enabled = true;
392- ToolStripMenuItem_OtherCommand.Enabled = true;
393- this.notifyIcon_MainForm.Text = "Running as GUI - " + vmxName;
394- this.notifyIcon_MainForm.BalloonTipText = this.notifyIcon_MainForm.Text;
395- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_run;
396- break;
397- case MENU_MODE.RUNNING_NOGUI:
398- ToolStripMenuItem_GoGUI.Enabled = true;
399- ToolStripMenuItem_GoNoGUI.Enabled = false;
400- ToolStripMenuItem_GoSuspend.Enabled = true;
401- ToolStripMenuItem_OtherCommand.Enabled = true;
402- this.notifyIcon_MainForm.Text = "Running as NoGUI - " + vmxName;
403- this.notifyIcon_MainForm.BalloonTipText = this.notifyIcon_MainForm.Text;
404- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_run;
405- break;
406- case MENU_MODE.PROCESSING:
407- ToolStripMenuItem_GoGUI.Enabled = false;
408- ToolStripMenuItem_GoNoGUI.Enabled = false;
409- ToolStripMenuItem_GoSuspend.Enabled = false;
410- ToolStripMenuItem_OtherCommand.Enabled = false;
411- this.notifyIcon_MainForm.Text = "Processing - " + vmxName;
412- this.notifyIcon_MainForm.BalloonTipText = this.notifyIcon_MainForm.Text;
413- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_proc;
414- break;
415- case MENU_MODE.SUSPENDED:
416- ToolStripMenuItem_GoGUI.Enabled = true;
417- ToolStripMenuItem_GoNoGUI.Enabled = true;
418- ToolStripMenuItem_GoSuspend.Enabled = false;
419- ToolStripMenuItem_OtherCommand.Enabled = false;
420- this.notifyIcon_MainForm.Text = "Suspended - " + vmxName;
421- this.notifyIcon_MainForm.BalloonTipText = this.notifyIcon_MainForm.Text;
422- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_suspend;
423- break;
424- case MENU_MODE.POWERED_OFF:
425- ToolStripMenuItem_GoGUI.Enabled = true;
426- ToolStripMenuItem_GoNoGUI.Enabled = true;
427- ToolStripMenuItem_GoSuspend.Enabled = false;
428- ToolStripMenuItem_OtherCommand.Enabled = false;
429- this.notifyIcon_MainForm.Text = "Powered OFF - " + vmxName;
430- this.notifyIcon_MainForm.BalloonTipText = this.notifyIcon_MainForm.Text;
431- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_stop;
432- break;
433- case MENU_MODE.CANNOT_DEFINE_RUNNING_MODE:
434- ToolStripMenuItem_GoGUI.Enabled = false;
435- ToolStripMenuItem_GoNoGUI.Enabled = false;
436- ToolStripMenuItem_GoSuspend.Enabled = true;
437- ToolStripMenuItem_OtherCommand.Enabled = true;
438- this.notifyIcon_MainForm.Text = "Running as ether GUI/NoGUI - " + vmxName;
439- this.notifyIcon_MainForm.BalloonTipText = MSG_BALN_WARN;
440- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_run;
441- this.notifyIcon_MainForm.ShowBalloonTip(500); // バルーンTip表示
442- break;
443- case MENU_MODE.NO_VMXFILE:
444- ToolStripMenuItem_GoGUI.Enabled = false;
445- ToolStripMenuItem_GoNoGUI.Enabled = false;
446- ToolStripMenuItem_GoSuspend.Enabled = false;
447- ToolStripMenuItem_OtherCommand.Enabled = false;
448- this.notifyIcon_MainForm.Text = "Can't find vmx file - " + vmxName;
449- this.notifyIcon_MainForm.BalloonTipText = "\"" + vmxName + MSG_BALN_NO_VMX_FILE;
450- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_err;
451- this.notifyIcon_MainForm.ShowBalloonTip(500); // バルーンTip表示
452- break;
453- case MENU_MODE.ERROR:
454- default:
455- ToolStripMenuItem_GoGUI.Enabled = false;
456- ToolStripMenuItem_GoNoGUI.Enabled = false;
457- ToolStripMenuItem_GoSuspend.Enabled = false;
458- ToolStripMenuItem_OtherCommand.Enabled = false;
459- this.notifyIcon_MainForm.Text = "Error - " + vmxName;
460- this.notifyIcon_MainForm.BalloonTipText = this.notifyIcon_MainForm.Text;
461- this.notifyIcon_MainForm.Icon = Properties.Resources.VMwPlayerTaskTray_err;
462- // Exit
463- MessageBox.Show(MSG_VIX_ERR, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
464- this.notifyIcon_MainForm.Visible = false; // タスクトレイからアイコンを取り除く
465- Application.Exit(); // アプリケーション終了
466- break;
467- }
468- }
469-
470- private bool confirmDialog()
471- {
472- DialogResult result = MessageBox.Show(MSG_CONFIRM, PROGRAM_NAME, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
473- switch (result)
474- {
475- case DialogResult.Cancel:
476- return false;
477- case DialogResult.OK:
478- default:
479- return true;
480- }
481- }
482-
483- private int CountProcess(string processName, string distinctinArgument)
484- {
485- int count = 0;
486- ManagementPath mngmntPath = new ManagementPath("Win32_Process");
487- ManagementClass mngmntClass = new ManagementClass(mngmntPath);
488-
489- ManagementObjectCollection mngmntObjClctn = mngmntClass.GetInstances();
490- foreach (ManagementObject obj in mngmntObjClctn)
491- {
492- object commandLineObj = obj["CommandLine"];
493- if (commandLineObj != null)
494- {
495- string commandLine = commandLineObj.ToString();
496- if ((0 <= commandLine.IndexOf(processName)) && (0 <= commandLine.IndexOf(distinctinArgument)))
497- {
498- count += 1; // runnning
499- }
500- }
501- }
502- return count;
503- }
504-
505- private void AboutDialog()
506- {
507- string message;
508-
509- //AssemblyTitleの取得
510- AssemblyTitleAttribute asmTitle = (AssemblyTitleAttribute)Attribute.GetCustomAttribute(
511- Assembly.GetExecutingAssembly(), typeof(AssemblyTitleAttribute));
512- //AssemblyDescriptionの取得
513- AssemblyDescriptionAttribute asmDesc = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
514- Assembly.GetExecutingAssembly(), typeof(AssemblyDescriptionAttribute));
515- //AssemblyCompanyの取得
516- AssemblyCompanyAttribute asmCompany = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(
517- Assembly.GetExecutingAssembly(), typeof(AssemblyCompanyAttribute));
518- //AssemblyProductの取得
519- AssemblyProductAttribute asmPrdct = (AssemblyProductAttribute)Attribute.GetCustomAttribute(
520- Assembly.GetExecutingAssembly(), typeof(AssemblyProductAttribute));
521- //AssemblyCopyrightの取得
522- AssemblyCopyrightAttribute asmCpyrght = (AssemblyCopyrightAttribute)Attribute.GetCustomAttribute(
523- Assembly.GetExecutingAssembly(), typeof(AssemblyCopyrightAttribute));
524- //AssemblyTrademarkの取得
525- AssemblyTrademarkAttribute asmTM = (AssemblyTrademarkAttribute)Attribute.GetCustomAttribute(
526- Assembly.GetExecutingAssembly(), typeof(AssemblyTrademarkAttribute));
527- //バージョンの取得
528- Assembly asm = Assembly.GetExecutingAssembly();
529- Version ver = asm.GetName().Version;
530-
531- message = asmTitle.Title + "\r\n" +
532- "\r\n" +
533- asmDesc.Description + "\r\n" +
534- "\r\n" +
535- MSG_ABOUT + "\r\n" +
536- "\r\n" +
537- asmCompany.Company + "\r\n" +
538- asmPrdct.Product + " Rev. " + ver + "\r\n" +
539- asmCpyrght.Copyright + "\r\n";
540- MessageBox.Show(message, PROGRAM_NAME, MessageBoxButtons.OK, MessageBoxIcon.Information);
541- }
542-
543- private bool movePlayerWindow(int left, int top)
544- {
545- CtrlVIX Vix = new CtrlVIX();
546-
547- int pid = Vix.GetVMProcessID(vmxFilePath);
548-
549- if (pid != 0)
550- {
551- if (moveWindow(pid, left, top, "VMPlayerFrame")) // Windowを移動する
552- {
553- return true;
554- }
555- }
556- return false;
557- }
558-
559- private bool getPlayerWindowPos(out int left, out int top)
560- {
561- CtrlVIX Vix = new CtrlVIX();
562- int pid = Vix.GetVMProcessID(vmxFilePath);
563-
564- if (pid != 0)
565- {
566- if (getWindowPos(pid, out left, out top, "VMPlayerFrame")) // Windowの top, leftを取得する
567- {
568- return true;
569- }
570- }
571- left = 0; top = 0;
572- return false;
573- }
574-
575- [StructLayout(LayoutKind.Sequential, Pack = 4)]
576- public struct RECT
577- {
578- public int Left { get; set; }
579- public int Top { get; set; }
580- public int Right { get; set; }
581- public int Bottom { get; set; }
582- }
583-
584- internal class NativeMethods
585- {
586- [DllImport("user32.dll", EntryPoint = "GetParent", SetLastError = true)]
587- public static extern IntPtr GetParent(IntPtr hwnd);
588- [DllImport("user32.dll", EntryPoint = "GetWindow", SetLastError = true)]
589- public static extern IntPtr GetWindow(IntPtr hWnd, int wCmd);
590- [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
591- public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
592- [DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId", SetLastError = true)]
593- public static extern Int32 GetWindowThreadProcessId(IntPtr hWnd, out int lpdwprocessid);
594- [DllImport("user32.dll", EntryPoint = "IsWindowVisible", SetLastError = true)]
595- public static extern int IsWindowVisible(IntPtr hWnd);
596- [DllImport("user32.dll", EntryPoint = "GetAncestor", SetLastError = true)]
597- public static extern IntPtr GetAncestor(IntPtr hWnd, uint gaFlags);
598- [DllImport("user32.dll", EntryPoint = "GetWindowRect", SetLastError = true)]
599- public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
600- [DllImport("user32.dll", EntryPoint = "MoveWindow", SetLastError = true)]
601- public static extern bool MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight, int bRepaint);
602- [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
603- public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, StringBuilder lParam);
604- [DllImport("user32.dll", EntryPoint = "GetWindowText", SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
605- public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
606- [DllImport("user32.dll", EntryPoint = "GetWindowTextLength", SetLastError = true)]
607- public static extern int GetWindowTextLength(IntPtr hWnd);
608- [DllImport("user32.dll", EntryPoint = "GetClassName", SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
609- public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
610- [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true, BestFitMapping = false, ThrowOnUnmappableChar = true)]
611- public static extern IntPtr FindWindowEx(IntPtr hWndParent, IntPtr hWndChildAfter, String lpszClass, String lpszWindow);
612- }
613-
614- // 指定したPIDのWindowを移動させる
615- private bool moveWindow(int pid, int left, int top, string classname)
616- {
617- RECT rect = new RECT();
618- rect.Left = 0; rect.Top = 0; rect.Right = 0; rect.Bottom = 0;
619- const int bRepaint_TRUE = 1; // TRUE for MoveWindow() = redraw
620- IntPtr hWnd = IntPtr.Zero;
621- IntPtr hWndChildAfter = IntPtr.Zero;
622-
623- if ((hWnd = getHwndFromPid(pid, classname)) == IntPtr.Zero)
624- {
625- return false;
626- }
627- if (!NativeMethods.GetWindowRect(hWnd, out rect))
628- {
629- return false;
630- }
631- if (!NativeMethods.MoveWindow(hWnd, left, top, rect.Right - rect.Left, rect.Bottom - rect.Top, bRepaint_TRUE))
632- {
633- return false;
634- }
635- System.Threading.Thread.Sleep(1000);
636- if (!NativeMethods.GetWindowRect(hWnd, out rect))
637- {
638- return false;
639- }
640- if (rect.Left != left || rect.Top != top)
641- {
642- return false;
643- }
644- return true;
645- }
646-
647- // 指定したPIDのWindowのleft topを取得する
648- private bool getWindowPos(int pid, out int left, out int top, string classname)
649- {
650- RECT rect = new RECT();
651- rect.Left = 0; rect.Top = 0; rect.Right = 0; rect.Bottom = 0;
652- IntPtr hWnd = IntPtr.Zero;
653- IntPtr hWndChildAfter = IntPtr.Zero;
654-
655- left = 0; top = 0;
656-
657- if ((hWnd = getHwndFromPid(pid, classname)) == IntPtr.Zero)
658- {
659- return false;
660- }
661- if (!NativeMethods.GetWindowRect(hWnd, out rect))
662- {
663- return false;
664- }
665- left = rect.Left; top = rect.Top;
666- return true;
667- }
668-
669- // プロセスID(pid)をウィンドウハンドル(hWnd)に変換する
670- private IntPtr getHwndFromPid(int pid, string classname)
671- {
672- IntPtr hWnd;
673- const int GW_HWNDNEXT = 2; // for GetWindow()
674- // GetAncestor()
675- // const uint GA_PARENT = 1;
676- // const uint GA_ROOT = 2;
677- // const uint GA_ROOTOWNER = 3;
678- // IntPtr parent = IntPtr.Zero, root = IntPtr.Zero, rootowner=IntPtr.Zero;
679- StringBuilder csb = new StringBuilder(256);
680-
681- hWnd = NativeMethods.FindWindow(null, null);
682- while (hWnd != IntPtr.Zero)
683- {
684- if (NativeMethods.GetParent(hWnd) == IntPtr.Zero && NativeMethods.IsWindowVisible(hWnd) != 0)
685- {
686- if (pid == getPidFromHwnd(hWnd))
687- {
688- NativeMethods.GetClassName(hWnd, csb, csb.Capacity);
689- if (0 <= csb.ToString().IndexOf(classname))
690- {
691-#if DEBUG
692-
693- Debug.WriteLine("ClassName = " + csb.ToString());
694-#endif
695- return hWnd;
696- }
697- //return rootowner; // 現在のではなくてひとつ前のroot ownerを返す
698- }
699- }
700- // parent = GetAncestor(hWnd, GA_PARENT);
701- // root = GetAncestor(hWnd, GA_ROOT);
702- // rootowner = GetAncestor(hWnd, GA_ROOTOWNER);
703- hWnd = NativeMethods.GetWindow(hWnd, GW_HWNDNEXT);
704- }
705- return IntPtr.Zero;
706- }
707-
708- // ウィンドウハンドル(hWnd)をプロセスID(pid)に変換する
709- private int getPidFromHwnd(IntPtr hWnd)
710- {
711- int pid;
712-
713- NativeMethods.GetWindowThreadProcessId(hWnd, out pid);
714- return pid;
715- }
716- }
717-}
--- a/VMwPlayerTaskTray/Program.cs
+++ /dev/null
@@ -1,62 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Threading.Tasks;
5-using System.Windows.Forms;
6-
7-namespace VMwPlayerTaskTray
8-{
9- static class Program
10- {
11- // グローバル変数
12- public static string vmxFilePath = "";
13- public static string startMode = "";
14- public static bool moveWindow = false;
15- public static int moveWindow_left;
16- public static int moveWindow_top;
17-
18- /// <summary>
19- /// アプリケーションのメイン エントリ ポイントです。
20- /// </summary>
21- [STAThread]
22- static void Main()
23- {
24-
25- Application.EnableVisualStyles();
26- Application.SetCompatibleTextRenderingDefault(false);
27- // 分けて処理をして最初にフォームを表示しないようにする
28- // Application.Run(new Form1());
29-
30- string[] cmds = System.Environment.GetCommandLineArgs();
31- for(int i=0; i < cmds.Length; i++)
32- {
33- if ((0 <= cmds[i].IndexOf(":\\")) && (0 <= cmds[i].IndexOf(".vmx")))
34- {
35- vmxFilePath = cmds[i];
36- }
37- else if ((0 <= cmds[i].IndexOf("/gui") || (0 <= cmds[i].IndexOf("/nogui"))))
38- {
39- startMode = cmds[i];
40- }
41- else if (0 <= cmds[i].IndexOf("/pos"))
42- {
43- int x, y;
44-
45- if (int.TryParse(cmds[i+1], out x) && int.TryParse(cmds[i+2], out y))
46- {
47- moveWindow_left = x;
48- moveWindow_top = y;
49- moveWindow = true;
50- i += 2;
51- }
52- }
53- }
54- new MainForm();
55-
56- if (vmxFilePath != "")
57- {
58- Application.Run();
59- }
60- }
61- }
62-}
Binary files a/VMwPlayerTaskTray/VMwPlayerTaskTray.ico and /dev/null differ
Binary files a/VMwPlayerTaskTray/VMwPlayerTaskTray_err.ico and /dev/null differ
Binary files a/VMwPlayerTaskTray/VMwPlayerTaskTray_proc.ico and /dev/null differ
Binary files a/VMwPlayerTaskTray/VMwPlayerTaskTray_run.ico and /dev/null differ
Binary files a/VMwPlayerTaskTray/VMwPlayerTaskTray_suspend.ico and /dev/null differ