-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathWmiFile.cs
55 lines (43 loc) · 1.86 KB
/
WmiFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Diagnostics;
namespace MemCacheDManager
{
public class WmiFile
{
public static bool DoesFileExist(string machineName, string userName, string password, string fileName)
{
ManagementScope scope = WmiHelper.Connect(machineName, userName, password);
SelectQuery selectQuery = new SelectQuery(string.Format(@"SELECT * FROM CIM_DataFile WHERE Name = '{0}'", fileName.Replace("\\", "\\\\")));
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, selectQuery);
if (searcher.Get().Count > 0)
return true;
else
return false;
}
public static bool DoesDirectoryExist(string machineName, string userName, string password, string directory)
{
ManagementScope scope = WmiHelper.Connect(machineName, userName, password);
SelectQuery selectQuery = new SelectQuery(string.Format(@"SELECT * FROM Win32_Directory WHERE Name = '{0}'", directory.Replace("\\", "\\\\")));
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, selectQuery);
if (searcher.Get().Count > 0)
return true;
else
return false;
}
public static void CreateDirectory(string machineName, string userName, string password, string directory)
{
ManagementScope scope = WmiHelper.Connect(machineName, userName, password);
string workingFolder = null;
string startupConfig = null;
IntPtr processID = IntPtr.Zero;
WmiHelper.InvokeStaticMethod(machineName, userName, password, "Win32_Process", "Create", new object[] { "cmd.exe /c mkdir \"" + directory + "\"", workingFolder, startupConfig, processID });
}
public static void CopyFileToRemoteMachine(string machineName, string userName, string password, string localFileName, string remoteFileName)
{
//WmiHelper.InvokeInstanceMethod(machine, "CIM_DataFile", "
}
}
}