VB.Net/Windows System/Environment Setting
Версия от 16:40, 26 мая 2010; (обсуждение)
Содержание
- 1 Adding Favorites
- 2 Display System Stack Trace
- 3 Get Environment Variable by Name
- 4 Get Machine Name
- 5 Get .Net Runtime Environment Version Number
- 6 Get OS Version
- 7 Get Processor Count
- 8 Get Sysstem Directory
- 9 Get System Exit Code
- 10 Get System New Line Code
- 11 Get Tick Count
- 12 Get Working Set
- 13 Has Shutdown Started
- 14 List your environment Setting
Adding Favorites
Public Class MainClass
Public Shared Sub Main()
CreateShortcut("Demo", "http://www.a.net/")
End Sub
Public Shared Sub CreateShortcut(ByVal Title As String, ByVal URL As String)
Dim strFavoriteFolder As String
strFavoriteFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
Dim objWriter As System.IO.StreamWriter = System.IO.File.CreateText(strFavoriteFolder & "\" & Title & ".url")
objWriter.WriteLine("[InternetShortcut]")
objWriter.WriteLine("URL=" & URL)
objWriter.Close()
End Sub
End Class
Display System Stack Trace
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("StackTrace: " & System.Environment.StackTrace )
End Sub
End Class
Get Environment Variable by Name
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine(Environ("USERNAME"))
End Sub
End Class
Get Machine Name
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("MachineName: " & System.Environment.MachineName)
End Sub
End Class
Get .Net Runtime Environment Version Number
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("Version: " & System.Environment.Version.ToString)
End Sub
End Class
Get OS Version
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("OSVersion: " & System.Environment.OSVersion.VersionString)
End Sub
End Class
Get Processor Count
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("ProcessorCount: " & System.Environment.ProcessorCount)
End Sub
End Class
Get Sysstem Directory
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("SystemDirectory: " & System.Environment.SystemDirectory)
End Sub
End Class
Get System Exit Code
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("ExitCode: " & System.Environment.ExitCode )
End Sub
End Class
Get System New Line Code
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("NewLine: " & System.Environment.NewLine)
End Sub
End Class
Get Tick Count
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("TickCount: " & System.Environment.TickCount)
End Sub
End Class
Get Working Set
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("WorkingSet: " & System.Environment.WorkingSet)
End Sub
End Class
Has Shutdown Started
Imports System
Public Class MainClass
Shared Sub Main()
Console.WriteLine("HasShutdownStarted: " & System.Environment.HasShutdownStarted )
End Sub
End Class
List your environment Setting
Imports System
Public Class MainClass
Shared Sub Main()
For i As Integer = 1 To 255
If Environ(i).Length = 0 Then Exit For
Console.WriteLine( Environ(i) )
Next i
End Sub
End Class