如何在.NET(based on c#)中调用系统功能
.net(based on c#)的功能无比强大,但是在系统文件操作方面还不能让程序员有天马行空的感觉。
于是很自然的想法是:如何用c#让世界上最聪明的人在代码的世界里,畅通无阻。让我们体验飞的感觉。
答案:vbscript:基于系统操作的vbs文件,可以让我们无所不能。(注意:我说的是基于IT Pro的vbs,而不是 基于IE的vbs).
步骤:(1):写好vbs文件,保存到E盘下。 such as:
ParentFolder = "."
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.NameSpace(ParentFolder)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
For Each objItem in colItems
If objItem.Month < 10 And objItem.Day < 10 Then
ChildFolderName = "0" & objItem.Year-2000 & "0" & objItem.Month & "0" & objItem.Day & "vbscript"
objFolder.NewFolder ChildFolderName
ChildFolder1 = "." & childFolderName
set objChildShell1 = CreateObject("Shell.Application")
set objChildFolder1 = objChildShell1.NameSpace(ChildFolder1)
objChildFolder1.NewFolder "Comparison"
objChildFolder1.NewFolder "CSV Files"
objChildFolder1.NewFolder "SUS BVT SP1"
objChildFolder1.NewFolder "Validation"
ElseIf objItem.Month < 10 And objItem.Day > 10 Then
ChildFolderName = "0" & objItem.Year-2000 & "0" & objItem.Month & objItem.Day & "vbscript"
objFolder.NewFolder ChildFolderName
ChildFolder2 = "." & childFolderName
set objChildShell2 = CreateObject("Shell.Application")
set objChildFolder2 = objChildShell2.NameSpace(ChildFolder1)
objChildFolder2.NewFolder "Comparison"
objChildFolder2.NewFolder "CSV Files"
objChildFolder2.NewFolder "SUS BVT SP1"
objChildFolder2.NewFolder "Validation"
ElseIf objItem.Day < 10 And objItem.Month > 10 Then
ChildFolderName = "0" & objItem.Year-2000 & objItem.Month & "0" & objItem.Day & "vbscript"
objFolder.NewFolder ChildFolderName
ChildFolder3 = "." & childFolderName
set objChildShell3 = CreateObject("Shell.Application")
set objChildFolder3 = objChildShell3.NameSpace(ChildFolder1)
objChildFolder3.NewFolder "Comparison"
objChildFolder3.NewFolder "CSV Files"
objChildFolder3.NewFolder "SUS BVT SP1"
objChildFolder3.NewFolder "Validation"
Else
ChildFolderName = "0" & objItem.Year-2000 & objItem.Month & objItem.Day & "vbscript"
objFolder.NewFolder ChildFolderName
ChildFolder4 = "." & childFolderName
set objChildShell4 = CreateObject("Shell.Application")
set objChildFolder4 = objChildShell4.NameSpace(ChildFolder1)
objChildFolder4.NewFolder "Comparison"
objChildFolder4.NewFolder "CSV Files"
objChildFolder4.NewFolder "SUS BVT SP1"
objChildFolder4.NewFolder "Validation"
End If
Next
(2):在.net中调用这个文件
System.Diagnostics.Process.Start("E:\\CreateFolder.vbs");
ok,一切就是这样简单。一切就是这样完美。呵呵!!!