Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

Search Results for "system" in [All]

getuname

.

System.Environment.UserName

.

If you want to obtain (localized) names of Unicode characters, instead calling this function you can also load strings from the same place the function loads them. On Windows 7 it means from file \System32\{Culture}\getuname.dll.mui. ({Culture} is name of culture you want to obtain localized resources for e.g. en-US). An advantage of this approach is that you can choose culture without need to switch current Windows language (Windows Ultimate edition only).

.

     Private Declare Function GetUName Lib "getuname.dll" (ByVal wCharCode As UShort, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpbuf As System.Text.StringBuilder) As Integer

.

     ''' Localized name of character represented by <paramref name="codePoint"/>. The name is localized to current system locale, not to current thread UI culture.

.

     ''' <para>This function relies on undocumented Windows API <c>GetUName</c>. It is possible that this API will be changed or removed in future version of Windows and this function will become slow and start returning nullls for all calls. It can also possibly carsh your application or system. Use on own risk.</para>

hhctrl

.

System.Windows.Forms.Help.ShowHelp()

.

        public static COLORREF FromColor(System.Drawing.Color aColor)

.

        public static System.Drawing.Color ToColor(COLORREF aColorRef)

.

System.Windows.Forms.Help.ShowPopup()

ntdsapi

.

using System;

.

using System.Runtime.ConstrainedExecution;

.

using System.Runtime.InteropServices;

.

using System.Security;

.

        throw new System.ComponentModel.Win32Exception((int)res);

.

        throw new System.Security.SecurityException("Unable to resolve user name.");

.

        throw new System.ComponentModel.Win32Exception((int)err);

.

         System.Diagnostics.Debug.WriteLineIf(ret != 0, "Error unbinding :\t" + ret.ToString());

.

System.DirectoryServices.ActiveDirectory.

.

    using System;

.

    using System.Runtime.InteropServices;

.

            // now copy the system allocated memory to our final (managed) array

wininet

.

    Dim s As New System.Text.StringBuilder

.

    ByVal hInternetSession As System.IntPtr,

.

    ByVal lContext As System.IntPtr) As System.IntPtr

.

[System.Runtime.InteropServices.DllImport("Wininet.dll")]

.

///     Retrieves the connected state of the local system.

.

///         Local system has a valid connection to the Internet, but it might or might not be currently

.

///         <description>Local system uses a local area network to connect to the Internet.</description>

.

///         <description>Local system uses a modem to connect to the Internet.</description>

.

///         <description>Local system is in offline mode.</description>

.

///         <description>Local system uses a proxy server to connect to the Internet.</description>

.

///         <description>Local system has RAS installed.</description>

.

using System;

.

using System.Runtime.InteropServices;

.

Try NetworkInterface.GetIsNetworkAvailable() in the the System.Net.NetworkInformation namespace. It returns true when a network is available and false otherwise. See also: http://msdn2.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getisnetworkavailable(VS.80).aspx. NOTE: this is all new in .NET 2.0!

.

static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);

.

    ByVal pchCookieData As System.Text.StringBuilder, ByRef pcchCookieData As Integer, ByVal flags As Integer, ByVal reserved As Integer) As _

.

    <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean

.

    static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);

.

static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref System.UInt32 pcchCookieData, int dwFlags, IntPtr lpReserved);

.

    ByVal pchCookieData As System.Text.StringBuilder, ByRef pcchCookieData As Integer, ByVal flags As Integer, ByVal reserved As Integer) As _

.

    <System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)> Boolean

.

     System.Object nullObject = 0;

.

     System.Object nullObjStr = strTemp;

.

Above signature is not working for x64 systems. See INTERNET_CACHE_ENTRY_INFO for a version that works on both x86 and x64.

.

    Private Sub cmdGetPolicy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetPolicy.Click

.

    'sBuffer = System.Runtime.InteropServices.Marshal.AllocHGlobal(dwBufferLength)

.

        MsgBox("1st Party: There was an error: Code " & CStr(System.Runtime.InteropServices.Marshal.GetLastWin32Error()))

.

    Private Sub cmdSetPolicy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSetPolicy.Click

.

        MsgBox("There was an error: Code " & CStr(System.Runtime.InteropServices.Marshal.GetLastWin32Error()))

ntdll

.

        System.IO.FileAccess access,

.

        System.IO.FileShare share,

.

objAttributes.Length = System.Convert.ToInt32(Marshal.SizeOf(objAttributes));

.

                System.Convert.ToUInt32(0),

.

                System.IO.FileShare.Read ,

.

                IntPtr.Zero, System.Convert.ToUInt32(0));

.

     System.Diagnostics.Debug.Print(

.

using System;

.

using System.Runtime.InteropServices; // for DllImport and friends

.

using System.Collections.Generic; // for ParseFileAttributes helper function (List<FileAttributes> only

.

using System.IO; // for test main (FileStream) only

.

using System.Text; // for test main (Encoding) only

.

using System.Threading; // for test main (Thread.Sleep) only

.

using System.Diagnostics; // for test main (Trace.Write[Line]) only

.

            FileAttributes.System,

.
Summary
Retrieves the specified system information. Specify the information you want, a pointer to hold the results.
.

/// <summary>Retrieves the specified system information.</summary>

.

/// <param name="InfoClass">indicate the kind of system information to be retrieved</param>

.

public static extern NtStatus NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS InfoClass, IntPtr Info, uint Size, out uint Length);

.

Declare Function NtQuerySystemInformation Lib "ntdll.dll" (TODO) As TODO

.

NtStatus, SYSTEM_INFORMATION_CLASS

.

public static IntPtr NtQuerySystemInformation(SYSTEM_INFORMATION_CLASS infoClass, uint infoLength = 0)

.

        var result = NtQuerySystemInformation(infoClass, infoPtr, infoLength, out infoLength);

.

    NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION

.

        result = (UInt32)NativeMethods.NtQuerySystemInformation(NativeMethods.SYSTEM_INFORMATION_CLASS.SystemMemoryListInformation, buff, result, out returnSize);

.

            throw new System.ComponentModel.Win32Exception(((NativeMethods.NtStatus)result).ToString());

.

        if (NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION_SIZE == 0)

.

            NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION_SIZE = returnSize;

.

        MemoryList = (NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION)Marshal.PtrToStructure(buff, typeof(NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION));

.
Documentation
[NtQuerySystemInformation] on MSDN
.

public static extern uint NtQuerySystemTime(out long SystemTime);

.

Declare Function NtQuerySystemTime Lib "ntdll.dll" (Currency) As TODO

.

NtQuerySystemTime(out t);

.
Documentation
[NtQuerySystemTime] on MSDN
.
Summary
Returns the resolution of the system Timer in the context of the calling process.
.
Summary
Change Windows System parameters
.

/// <summary>Change Windows System parameters</summary>

.

static extern UInt32 NtSetSystemInformation(NtSystemInformation.SYSTEM_INFORMATION_CLASS InfoClass, IntPtr Info, UInt32 Length);

.

Declare Function NtSetSystemInformation Lib "ntdll.dll" (TODO) As TODO

.

This works in the same manner as NtQuerySystemInformation.

.

public static void SetSystemInformation(NtSystemInformation.SYSTEM_INFORMATION_CLASS InfoClass, IntPtr Info, UInt32 Length)

.

        result = NtSetSystemInformationKernel(InfoClass, Info, Length);

.
Documentation
[NtSetSystemInformation] on MSDN
.
Summary
Sets the resolution of the system Timer in the calling process context.
.
Summary
Tells NtQuerySystemInformation and NtSetSystemInformation what you would like to read/change.
.

public enum SYSTEM_INFORMATION_CLASS

.

    SystemBasicInformation = 0x0000,

.

    SystemProcessorInformation = 0x0001,

.

    SystemPerformanceInformation = 0x0002,

.

    SystemTimeOfDayInformation = 0x0003,

.

    SystemPathInformation = 0x0004,

.

    SystemProcessInformation = 0x0005,

.

    SystemCallCountInformation = 0x0006,

.

    SystemDeviceInformation = 0x0007,

.

    SystemProcessorPerformanceInformation = 0x0008,

.

    SystemFlagsInformation = 0x0009,

.

    SystemCallTimeInformation = 0x000A,

.

    SystemModuleInformation = 0x000B,

.

    SystemLocksInformation = 0x000C,

.

    SystemStackTraceInformation = 0x000D,

.

    SystemPagedPoolInformation = 0x000E,

.

    SystemNonPagedPoolInformation = 0x000F,

.

    SystemHandleInformation = 0x0010,

.

    SystemObjectInformation = 0x0011,

.

    SystemPageFileInformation = 0x0012,

.

    SystemVdmInstemulInformation = 0x0013,

.

    SystemVdmBopInformation = 0x0014,

.

    SystemFileCacheInformation = 0x0015,

.

    SystemPoolTagInformation = 0x0016,

.

    SystemInterruptInformation = 0x0017,

.

    SystemDpcBehaviorInformation = 0x0018,

.

    SystemFullMemoryInformation = 0x0019,

.

    SystemLoadGdiDriverInformation = 0x001A,

.

    SystemUnloadGdiDriverInformation = 0x001B,

.

    SystemTimeAdjustmentInformation = 0x001C,

.

    SystemSummaryMemoryInformation = 0x001D,

.

    SystemMirrorMemoryInformation = 0x001E,

.

    SystemPerformanceTraceInformation = 0x001F,

.

    SystemCrashDumpInformation = 0x0020,

.

    SystemExceptionInformation = 0x0021,

.

    SystemCrashDumpStateInformation = 0x0022,

.

    SystemKernelDebuggerInformation = 0x0023,

.

    SystemContextSwitchInformation = 0x0024,

.

    SystemRegistryQuotaInformation = 0x0025,

.

    SystemExtendServiceTableInformation = 0x0026,

.

    SystemPrioritySeperation = 0x0027,

.

    SystemVerifierAddDriverInformation = 0x0028,

.

    SystemVerifierRemoveDriverInformation = 0x0029,

.

    SystemProcessorIdleInformation = 0x002A,

.

    SystemLegacyDriverInformation = 0x002B,

.

    SystemCurrentTimeZoneInformation = 0x002C,

.

    SystemLookasideInformation = 0x002D,

.

    SystemTimeSlipNotification = 0x002E,

.

    SystemSessionCreate = 0x002F,

.

    SystemSessionDetach = 0x0030,

.

    SystemSessionInformation = 0x0031,

.

    SystemRangeStartInformation = 0x0032,

.

    SystemVerifierInformation = 0x0033,

.

    SystemVerifierThunkExtend = 0x0034,

.

    SystemSessionProcessInformation = 0x0035,

.

    SystemLoadGdiDriverInSystemSpace = 0x0036,

.

    SystemNumaProcessorMap = 0x0037,

.

    SystemPrefetcherInformation = 0x0038,

.

    SystemExtendedProcessInformation = 0x0039,

.

    SystemRecommendedSharedDataAlignment = 0x003A,

.

    SystemComPlusPackage = 0x003B,

.

    SystemNumaAvailableMemory = 0x003C,

.

    SystemProcessorPowerInformation = 0x003D,

.

    SystemEmulationBasicInformation = 0x003E,

.

    SystemEmulationProcessorInformation = 0x003F,

.

    SystemExtendedHandleInformation = 0x0040,

.

    SystemLostDelayedWriteInformation = 0x0041,

.

    SystemBigPoolInformation = 0x0042,

.

    SystemSessionPoolTagInformation = 0x0043,

.

    SystemSessionMappedViewInformation = 0x0044,

.

    SystemHotpatchInformation = 0x0045,

.

    SystemObjectSecurityMode = 0x0046,

.

    SystemWatchdogTimerHandler = 0x0047,

.

    SystemWatchdogTimerInformation = 0x0048,

.

    SystemLogicalProcessorInformation = 0x0049,

.

    SystemWow64SharedInformationObsolete = 0x004A,

.

    SystemRegisterFirmwareTableInformationHandler = 0x004B,

.

    SystemFirmwareTableInformation = 0x004C,

.

    SystemModuleInformationEx = 0x004D,

.

    SystemVerifierTriageInformation = 0x004E,

.

    SystemSuperfetchInformation = 0x004F,

.

    SystemMemoryListInformation = 0x0050, // SYSTEM_MEMORY_LIST_INFORMATION

.

    SystemFileCacheInformationEx = 0x0051,

.

    SystemThreadPriorityClientIdInformation = 0x0052,

.

    SystemProcessorIdleCycleTimeInformation = 0x0053,

.

    SystemVerifierCancellationInformation = 0x0054,

.

    SystemProcessorPowerInformationEx = 0x0055,

.

    SystemRefTraceInformation = 0x0056,

.

    SystemSpecialPoolInformation = 0x0057,

.

    SystemProcessIdInformation = 0x0058,

.

    SystemErrorPortInformation = 0x0059,

.

    SystemBootEnvironmentInformation = 0x005A,

.

    SystemHypervisorInformation = 0x005B,

.

    SystemVerifierInformationEx = 0x005C,

.

    SystemTimeZoneInformation = 0x005D,

.

    SystemImageFileExecutionOptionsInformation = 0x005E,

.

    SystemCoverageInformation = 0x005F,

.

    SystemPrefetchPatchInformation = 0x0060,

.

    SystemVerifierFaultsInformation = 0x0061,

.

    SystemSystemPartitionInformation = 0x0062,

.

    SystemSystemDiskInformation = 0x0063,

.

    SystemProcessorPerformanceDistribution = 0x0064,

.

    SystemNumaProximityNodeInformation = 0x0065,

.

    SystemDynamicTimeZoneInformation = 0x0066,

.

    SystemCodeIntegrityInformation = 0x0067,

.

    SystemProcessorMicrocodeUpdateInformation = 0x0068,

.

    SystemProcessorBrandString = 0x0069,

.

    SystemVirtualAddressInformation = 0x006A,

.

    SystemLogicalProcessorAndGroupInformation = 0x006B,

.

    SystemProcessorCycleTimeInformation = 0x006C,

.

    SystemStoreInformation = 0x006D,

.

    SystemRegistryAppendString = 0x006E,

.

    SystemAitSamplingValue = 0x006F,

.

    SystemVhdBootInformation = 0x0070,

.

    SystemCpuQuotaInformation = 0x0071,

.

    SystemNativeBasicInformation = 0x0072,

.

    SystemErrorPortTimeouts = 0x0073,

.

    SystemLowPriorityIoInformation = 0x0074,

.

    SystemBootEntropyInformation = 0x0075,

.

    SystemVerifierCountersInformation = 0x0076,

.

    SystemPagedPoolInformationEx = 0x0077,

.

    SystemSystemPtesInformationEx = 0x0078,

.

    SystemNodeDistanceInformation = 0x0079,

.

    SystemAcpiAuditInformation = 0x007A,

.

    SystemBasicPerformanceInformation = 0x007B,

.

    SystemQueryPerformanceCounterInformation = 0x007C,

.

    SystemSessionBigPoolInformation = 0x007D,

.

    SystemBootGraphicsInformation = 0x007E,

.

    SystemScrubPhysicalMemoryInformation = 0x007F,

.

    SystemBadPageInformation = 0x0080,

.

    SystemProcessorProfileControlArea = 0x0081,

.

    SystemCombinePhysicalMemoryInformation = 0x0082,

.

    SystemEntropyInterruptTimingInformation = 0x0083,

.

    SystemConsoleInformation = 0x0084,

.

    SystemPlatformBinaryInformation = 0x0085,

.

    SystemThrottleNotificationInformation = 0x0086,

.

    SystemHypervisorProcessorCountInformation = 0x0087,

.

    SystemDeviceDataInformation = 0x0088,

.

    SystemDeviceDataEnumerationInformation = 0x0089,

.

    SystemMemoryTopologyInformation = 0x008A,

.

    SystemMemoryChannelInformation = 0x008B,

.

    SystemBootLogoInformation = 0x008C,

.

    SystemProcessorPerformanceInformationEx = 0x008D,

.

    SystemSpare0 = 0x008E,

.

    SystemSecureBootPolicyInformation = 0x008F,

.

    SystemPageFileInformationEx = 0x0090,

.

    SystemSecureBootInformation = 0x0091,

.

    SystemEntropyInterruptTimingRawInformation = 0x0092,

.

    SystemPortableWorkspaceEfiLauncherInformation = 0x0093,

.

    SystemFullProcessInformation = 0x0094,

.

    MaxSystemInfoClass = 0x0095

.

Declare Function SYSTEM_INFORMATION_CLASS Lib "ntdll.dll" (TODO) As TODO

.
Documentation
[SYSTEM_INFORMATION_CLASS] on MSDN
.
Summary
Structure returned by NtQuerySystemInformation in response to SYSTEM_INFORMATION_CLASS.SystemMemoryListInformation = 0x0050
.

public struct SYSTEM_MEMORY_LIST_INFORMATION // Size=88

.

Declare Function SYSTEM_MEMORY_LIST_INFORMATION Lib "ntdll.dll" (TODO) As TODO

.

    NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION

.

        result = (UInt32)NativeMethods.NtQuerySystemInformation(NativeMethods.SYSTEM_INFORMATION_CLASS.SystemMemoryListInformation, buff, result, out returnSize);

.

            throw new System.ComponentModel.Win32Exception(((NativeMethods.NtStatus)result).ToString());

.

        MemoryList = (NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION)Marshal.PtrToStructure(buff, typeof(NativeMethods.SYSTEM_MEMORY_LIST_INFORMATION));

.
Documentation
[SYSTEM_MEMORY_LIST_INFORMATION] on MSDN

mpr

.

[DllImport("mpr.dll", CharSet = System.Runtime.InteropServices.CharSet.Ansi)]

.

  //                              string lpUsername, System.UInt32 dwFlags );

.

  using System.Runtime.InteropServices;

.

using System.Runtime.InteropServices;

.

        Dim errorM = New System.ComponentModel.Win32Exception(returnValue).Message

.

The system updates the user profile with the information that the connection is no longer a persistent one if you pass this constant as <dwFlags>

.

The system updates the user profile with the information that the connection is no longer a persistent one if you pass this constant as <dwFlags>

.

    [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpLocalName;

.

    [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpRemoteName;

.

    [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpComment;

.

    [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)] public string lpProvider;

.

Imports System.Runtime.InteropServices

.

    <MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpLocalName As String

.

    <MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpRemoteName As String

.

    <MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpComment As String

.

    <MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpProvider As String

.

                      ByVal localName As String, ByVal remoteName As System.Text.StringBuilder, _

.

    Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal localName As String, ByVal remoteName As System.Text.StringBuilder, ByRef length As Integer) As Integer

.

    ByVal remoteName As System.Text.StringBuilder, ByRef length As Integer) As Integer

.

        Dim UNC As New System.Text.StringBuilder(length)

.

                      ByVal remoteName As System.Text.StringBuilder, _

setupapi

.
MSDN
This function is reserved for system use. Do not use this function in your class installers, co-installers, or device installation applications. Use device installation functions instead.
.

        '    System.Math.Max(System.Threading.Interlocked.Increment(memIndex), memIndex - 1)

.

    didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)

.

    static extern int CM_Request_Device_Eject(UInt32 devinst, out PNP_VETO_TYPE pVetoType, System.Text.StringBuilder pszVetoName, int ulNameLength, int ulFlags);

.

        System.Text.StringBuilder sb = new System.Text.StringBuilder(255);

.

            SP_COPY_IN_USE_NEEDS_REBOOT = 0x0000100,   // System needs reboot if file in use

.

            SP_COPY_WARNIFSKIP      = 0x0004000,   // system critical file: warn if user tries to skip

.

       didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)

.

       didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)

.

        public System.Runtime.InteropServices.ComTypes.FILETIME DriverDate;

.

       if (IntPtr.Size == 8) // for 64 bit operating systems

.

       didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // for 32 bit systems

.

    didd.cbSize = 6 '+' Marshal.SystemDefaultCharSize + Sizeof(intptr.zero)

.

http://stackoverflow.com/questions/4097000/how-do-i-disable-a-system-device-programatically

.

       didd.cbSize = 4 + Marshal.SystemDefaultCharSize; // trust me :)

.
FileName Pointer to a null-terminated string containing the name (and optional path) of the INF file to be opened. If the filename does not contain path separator characters, it is searched for, first in the \inf directory, and then in the \system32 directory. If the filename contains path separator characters, it is assumed to be a full path specification and no further processing is performed on it.

advapi32

.

        int lastError = System.Runtime.InteropServices.Marshal.GetLastWin32Error();

.

        case SecurityEntity.SE_SYSTEM_ENVIRONMENT_NAME:

.

           return "SeSystemEnvironmentPrivilege";

.

        case SecurityEntity.SE_SYSTEM_PROFILE_NAME:

.

           return "SeSystemProfilePrivilege";

.

        case SecurityEntity.SE_SYSTEMTIME_NAME:

.

           return "SeSystemtimePrivilege";

.

      SE_SYSTEM_PROFILE_NAME,

.

      SE_SYSTEMTIME_NAME,

.

      SE_SYSTEM_ENVIRONMENT_NAME,

.

      internal static extern bool LookupPrivilegeValue(string lpsystemname, string lpname, [MarshalAs(UnmanagedType.Struct)] ref LUID lpLuid);

.

     ByVal lpSystemName As String, _

.

            Throw New System.ComponentModel.Win32Exception(lastWin32Error, _

.

            Throw New System.ComponentModel.Win32Exception(lastWin32Error, _

.

                Throw New System.ComponentModel.Win32Exception(lastWin32Error, _

.

You will need to reference System.Runtime.InteropServices

.

EventLogSession from the namespace System.Diagnostics.Eventing.Reader can be used in most cases (Windows Vista and above only and .NET 4 or above. This throws a PlatformNotSupportedException on Windows XP and Windows 2003 with .NET 4)

.

BuildExplicitAccessWithName does not appear to work on x64 bit systems. Usually causes an AppCrash in compiled .net apps. Same code works when compiled as x86 app.

.

Most (but not all) functionality can be accessed using classes in the System.ServiceProcess namespace.

.

To open service you don't need to use Windows API (OpenSCManager() and OpenService()) use field of System.ServiceProcess.ServiceController class (ServiceController.ServiceHandle.DangerousGetHandle())

.

Most (but not all) functionality can be accessed using classes in the System.ServiceProcess namespace.

.

To open service you don't need to use Windows API (OpenSCManager() and OpenService()) use field of System.ServiceProcess.ServiceController class (ServiceController.ServiceHandle.DangerousGetHandle())

.

http://msdn.microsoft.com/es-es/library/system.diagnostics.eventlog.clear.aspx

.

using System;

.

using System.Runtime.InteropServices;

.

using System.Reflection;

.

using System.ServiceProcess;

.

using System.Threading;

.

         fieldInfo = typeof (System.ServiceProcess.ServiceBase).GetField ("statusHandle", bindingFlags);

.
Dissent
Don't use an IntPtr like above, just use a System.Text.StringBuilder. You shouldn't need to worry about calling LocalFree in this case either, but I have not confirmed this 100%.
.

     throw new System.ComponentModel.Win32Exception();

.

  System.Runtime.InteropServices.Marshal.Copy(SID, 0, sidPtr, SID.Length);

.

  System.Runtime.InteropServices.Marshal.FreeHGlobal( sidPtr );

.

       sSID = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptrSID)

.

       sSID = System.Runtime.InteropServices.Marshal.PtrToStringAuto(ptrSID)

.

     System.Runtime.InteropServices.Marshal.FreeHGlobal(ptrSID)

.

System.Security.Principal.SecurityIdentifier.ToString()

.

using System.Security.Principal;

.

   //SecurityIdentifier is defined in the System.Security.Principal namespace.

.

     ([System.Security.Principal.SecurityIdentifier]$strSid).GetBinaryForm($binarySid,0)

.

            System.Management.ManagementClass("Win32_Ace").CreateInstance();

.

        ManagementObject Trustee = new System.Management.ManagementClass("Win32_Trustee").CreateInstance();

.

System.IntPtr hToken;

.

Dim hToken as System.IntPtr

.

Imports System

.

Imports System.Runtime.InteropServices

.

    Public Infinite As System.UInt32 = Convert.ToUInt32(&HFFFFFFF)

.

    Dim exitCode As System.UInt32 = Convert.ToUInt32(123456)

.

    Dim domain As String = System.Environment.MachineName

.

    Dim currentDirectory As String = System.IO.Directory.GetCurrentDirectory()

.

using System;

.

using System.Runtime.InteropServices;

.

            String domain  = System.Environment.MachineName;

.

            String currentDirectory = System.IO.Directory.GetCurrentDirectory();

.

[System.Diagnostics.Process]

.
Note
For .NET 1.1, System.Diagnostics.Process only allows you to start processes that will run under the same user account as the process that created it.
.

For .NET 2.0, System.Diagnostics.Process.Start has new overloads that allows you to run under different user accounts.

.

    /// system checks the access token of the calling process.

.

    /// the right to change the executable file that the system runs,

.

    /// for ACCESS_SYSTEM_SECURITY access, and then disable the privilege.

.

    ACCESS_SYSTEM_SECURITY = ACCESS_MASK.ACCESS_SYSTEM_SECURITY,

.

    /// File system driver service.

.

    SERVICE_FILE_SYSTEM_DRIVER = 0x00000002,

.

    /// A device driver started by the system loader. This value is valid

.

    /// A device driver started by the IoInitSystem function. This value

.

    SERVICE_SYSTEM_START = 0x00000001,

.

    /// during system startup. For more information, see Automatically

.

    /// operation continues. Otherwise, the system is restarted with

.

    /// operation fails. Otherwise, the system is restarted with the

.

    ''' operation continues. Otherwise, the system is restarted with

.

    ''' operation fails. Otherwise, the system is restarted with the

.

    ''' system checks the access token of the calling process.

.

    ''' the right to change the executable file that the system runs

.

    ''' for ACCESS_SYSTEM_SECURITY access and then disable the privilege.

.

    ACCESS_SYSTEM_SECURITY = ACCESS_MASK.ACCESS_SYSTEM_SECURITY

.

    ''' File system driver service.

.

    SERVICE_FILE_SYSTEM_DRIVER = &H2

.

    ''' A device driver started by the system loader. This value is valid

.

    ''' A device driver started by the IoInitSystem function. This value

.

    SERVICE_SYSTEM_START = &H1

.

    ''' during system startup. For more information, see Automatically

.

System.ServiceProcess.ServiceInstaller - http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemServiceProcessServiceInstallerClassTopic.asp

.

using System.Security.Principal;

.

        CREATE_IGNORE_SYSTEM_DEFAULT    = 0x80000000,

.

    CREATE_IGNORE_SYSTEM_DEFAULT = &H80000000

.

    $cred.target = [System.Runtime.InteropServices.Marshal]::StringToCoTaskMemUni('server')

.

        public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;

.

            public System.Runtime.InteropServices.ComTypes.FILETIME LastWritten;

.

Use System.Text.Encoding.Unicode.GetString to convert the CredentialBlob into a password string.

Cut off search results after 60. Please refine your search.


 
Access PInvoke.net directly from VS: