How to catch UserName and Version? How to play audio file from special folder? You can benefit from blow code.
To get user's IDof current computer
using System.Security.Principal;
WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());
txtUserName.Text = wp.Identity.Name.Substring(wp.Identity.Name.IndexOf(@"\") + 1);
To get current version:
using System.Diagnostics;
public static string GetVersion()
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo("MySystem.exe");
return "System version ( " + fvi.FileVersion + " )";
}
To play audio file from special folder:
using System.Windows.Forms;
[System.Runtime.InteropServices.DllImport("winmm.dll", SetLastError = true)]
static extern bool PlaySound(string pszSound, System.UIntPtr hmod, uint fdwSound);
public static void play(string strFileName)
{
string strSoundPath = Application.StartupPath.Replace("bin", "WH").Replace("Debug", "Sound") + "\\";
PlaySound(strSoundPath+strFileName, UIntPtr.Zero, 0);
}
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15053694/viewspace-442173/
,如需转载,请注明出处,否则将追究法律责任。