コード例 #1
0
        /// <summary>
        /// Deletes a file or directory at the specified location.
        /// </summary>
        /// <param name="path">The path to the file or directory.</param>
        public static void DeleteFileOrDirectory(ManagementScope mgmtScope, String path, bool directory = false)
        {
            var wmiClass = directory
                ? "Win32_Directory"
                : "CIM_DataFile";

            WMI.WMIQuery_InvokeMethod(mgmtScope, String.Format("SELECT * FROM {0} WHERE Name = '{1}'", wmiClass, path), "Delete");
        }
コード例 #2
0
        /// <summary>
        /// Creates a file or folder at the specified location.
        /// </summary>
        /// <param name="path">The path to the file or directory.</param>
        /// <param name="directory">Boolean indicating file or directory.</param>
        public static void CreateFileOrDirectory(ManagementScope mgmtScope, String path, bool directory = false)
        {
            var dosCommand = directory
                ? "mkdir"
                : "ECHO Create >";
            var wmiCommand = String.Format("cmd.exe /c {0} \"{1}\"", dosCommand, path);

            WMI.MakeWMICall(mgmtScope, "Win32_Process", wmiCommand);
        }