Beispiel #1
0
        public static ShareReturnCode Create(string machineName, string shareName, string path, string description)
        {
            try
            {
                path = Path.GetFullPath(path);

                const string methodName = "Create";

                //todo: This only creates read only shares
                var parameters = new object[]
                {
                    path,                     // Path
                    shareName,                // Name
                    0x0,                      // Type
                    null,                     // MaximumAllowed
                    description,              // Description
                    null,                     // Password
                    null                      // Win32_SecurityDescriptor Access
                };
                return((ShareReturnCode)WmiHelper.InvokeStaticMethod(machineName, CLASSNAME, methodName, parameters));
            }
            catch
            {
                return(ShareReturnCode.UnknownFailure);
            }
        }
Beispiel #2
0
 public static ServiceReturnCode Pause(string machineName, string serviceName)
 {
     try
     {
         string methodName = "PauseService";
         return
             ((ServiceReturnCode)WmiHelper.InvokeInstanceMethod(machineName, CLASSNAME, serviceName, methodName));
     }
     catch
     {
         return(ServiceReturnCode.UnknownFailure);
     }
 }
Beispiel #3
0
        public static ShareReturnCode Delete(string serverName, string shareName)
        {
            var query = new WqlObjectQuery("select Name from Win32_Share");
            var scope = WmiHelper.Connect(serverName);

            using (var search = new ManagementObjectSearcher(scope, query))
            {
                foreach (ManagementObject share in search.Get())
                {
                    string name = share["Name"].ToString();
                    if (name.EqualsIgnoreCase(shareName))
                    {
                        share.Delete();
                        return(ShareReturnCode.Success);
                    }
                }
            }

            return(ShareReturnCode.UnknownFailure);
        }
Beispiel #4
0
        public static string GetLocalPathForShare(string serverName, string shareName)
        {
            var query = new WqlObjectQuery("select Name, Path from Win32_Share");
            var scope = WmiHelper.Connect(serverName);

            using (var search = new ManagementObjectSearcher(scope, query))
            {
                foreach (var share in search.Get())
                {
                    string name = share["Name"].ToString();
                    string path = share["Path"].ToString();

                    if (name.EqualsIgnoreCase(shareName))
                    {
                        return(path);
                    }
                }
            }
            throw new Exception("There is no share '{0}' on machine '{1}'".FormatWith(shareName, serverName));
        }
Beispiel #5
0
        //private char NULL_VALUE = char(0);

        public static ServiceReturnCode Create(string machineName, string serviceName, string serviceDisplayName,
                                               string serviceLocation, ServiceStartMode startMode, string userName,
                                               string password, string[] dependencies)
        {
            if (userName != null && userName.IndexOf('\\') < 0)
            {
                userName = "******" + userName;
            }

            try
            {
                const string methodName = "Create";


                var parameters = new object[]
                {
                    serviceName,                                // Name
                    serviceDisplayName,                         // Display Name
                    serviceLocation,                            // Path Name | The Location "E:\somewhere\something"
                    Convert.ToInt32(ServiceType.OwnProcess),    // ServiceType
                    Convert.ToInt32(ErrorControl.UserNotified), // Error Control
                    startMode.ToString(),                       // Start Mode
                    false,                                      // Desktop Interaction
                    userName,                                   // StartName | Username
                    password,                                   // StartPassword |Password
                    null,                                       // LoadOrderGroup | Service Order Group
                    null,                                       // LoadOrderGroupDependencies | Load Order Dependencies
                    dependencies                                //  ServiceDependencies
                };
                return((ServiceReturnCode)WmiHelper.InvokeStaticMethod(machineName, CLASSNAME, methodName, parameters));
            }
            catch
            {
                return(ServiceReturnCode.UnknownFailure);
            }
        }
Beispiel #6
0
 public static void WithAuthentication(string remoteUserName, string remotePassword)
 {
     WmiHelper.WithAuthentication(remoteUserName, remotePassword);
 }