- QueryDosDeviceW function (fileapi.h)
- Syntax
- Parameters
- Return value
- Remarks
- Is there a /dev/null on Windows?
- 7 Answers 7
- Not the answer you’re looking for? Browse other questions tagged windows or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- Specifying Device Types
- SetupDiGetClassDevsW function (setupapi.h)
- Syntax
- Parameters
- DIGCF_ALLCLASSES
- DIGCF_DEVICEINTERFACE
- DIGCF_DEFAULT
- DIGCF_PRESENT
- DIGCF_PROFILE
- Return value
- Remarks
- Device Setup Class Control Options
- Device Interface Class Control Options
- Examples
- CTL_CODE (Windows CE 5.0)
- Parameters
- Return Values
- Remarks
QueryDosDeviceW function (fileapi.h)
Retrieves information about MS-DOS device names. The function can obtain the current mapping for a particular MS-DOS device name. The function can also obtain a list of all existing MS-DOS device names.
MS-DOS device names are stored as junctions in the object namespace. The code that converts an MS-DOS path into a corresponding path uses these junctions to map MS-DOS devices and drive letters. The QueryDosDevice function enables an application to query the names of the junctions used to implement the MS-DOS device namespace as well as the value of each specific junction.
Syntax
Parameters
An MS-DOS device name string specifying the target of the query. The device name cannot have a trailing backslash; for example, use «C:», not «C:\».
This parameter can be NULL. In that case, the QueryDosDevice function will store a list of all existing MS-DOS device names into the buffer pointed to by lpTargetPath.
A pointer to a buffer that will receive the result of the query. The function fills this buffer with one or more null-terminated strings. The final null-terminated string is followed by an additional NULL.
If lpDeviceName is non-NULL, the function retrieves information about the particular MS-DOS device specified by lpDeviceName. The first null-terminated string stored into the buffer is the current mapping for the device. The other null-terminated strings represent undeleted prior mappings for the device.
If lpDeviceName is NULL, the function retrieves a list of all existing MS-DOS device names. Each null-terminated string stored into the buffer is the name of an existing MS-DOS device, for example, \Device\HarddiskVolume1 or \Device\Floppy0.
The maximum number of TCHARs that can be stored into the buffer pointed to by lpTargetPath.
Return value
If the function succeeds, the return value is the number of TCHARs stored into the buffer pointed to by lpTargetPath.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
If the buffer is too small, the function fails and the last error code is ERROR_INSUFFICIENT_BUFFER.
Remarks
The DefineDosDevice function enables an application to create and modify the junctions used to implement the MS-DOS device namespace.
Windows ServerВ 2003 and WindowsВ XP:В В QueryDosDevice first searches the Local MS-DOS Device namespace for the specified device name. If the device name is not found, the function will then search the Global MS-DOS Device namespace.
When all existing MS-DOS device names are queried, the list of device names that are returned is dependent on whether it is running in the «LocalSystem» context. If so, only the device names included in the Global MS-DOS Device namespace will be returned. If not, a concatenation of the device names in the Global and Local MS-DOS Device namespaces will be returned. If a device name exists in both namespaces, QueryDosDevice will return the entry in the Local MS-DOS Device namespace.
For more information on the Global and Local MS-DOS Device namespaces and changes to the accessibility of MS-DOS device names, see Defining an MS DOS Device Name.
In WindowsВ 8 and Windows ServerВ 2012, this function is supported by the following technologies.
Technology | Supported |
---|---|
Server Message Block (SMB) 3.0 protocol | No |
SMB 3.0 Transparent Failover (TFO) | No |
SMB 3.0 with Scale-out File Shares (SO) | No |
Cluster Shared Volume File System (CsvFS) | Yes |
Resilient File System (ReFS) | Yes |
В
SMB does not support volume management functions.
Is there a /dev/null on Windows?
What is the equivalent of /dev/null on Windows?
7 Answers 7
I think you want NUL , at least within a command prompt or batch files.
doesn’t create a file.
(I believe the same is true if you try to create a file programmatically, but I haven’t tried it.)
In PowerShell, you want $null :
According to this message on the GCC mailing list, you can use the file «nul» instead of /dev/null:
(Credits to Danny for this code; copy-pasted from his message.)
You can also use this special «nul» file through redirection.
NUL in Windows seems to be actually a virtual path in any folder. Just like .. , . in any filesystem.
Use any folder followed with NUL will work.
have the same effect as /dev/null on Linux.
This was tested on Windows 7, 64 bit.
Jon Skeet is correct. Here is the Nul Device Driver page in the Windows Embedded documentation (I have no idea why it’s not somewhere else. ).
Here is another:
NUL works programmatically as well. E.g. the following:
works as expected without creating a file. (MSVC++ 12.0)
If you need to perform in Microsoft Windows the equivalent of a symlink to /dev/null in Linux you would open and administrator’s cmd and type:
For files:
Or, for directories:
This will keep the file/direcotry always at 0 byte, and still return success to every write attempt.
You have to use start and $NUL for this in Windows PowerShell:
Type in this command assuming mySum is the name of your application and 5 10 are command line arguments you are sending.
The start command will start a detached process, a similar effect to & . The /B option prevents start from opening a new terminal window if the program you are running is a console application. and NUL is Windows’ equivalent of /dev/null . The 2>&1 at the end will redirect stderr to stdout, which will all go to NUL .
Not the answer you’re looking for? Browse other questions tagged windows or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Specifying Device Types
Each device object has a device type, which is stored in the DeviceType member of its DEVICE_OBJECT structure. The device type represents the type of underlying hardware for the driver.
Every kernel-mode driver that creates a device object must specify an appropriate device type value when calling IoCreateDevice. The IoCreateDevice routine uses the supplied device type to initialize the DeviceType member of the DEVICE_OBJECT structure.
The system defines the following device type values, listed in alphabetical order:
These constants are defined in Ntddk.h and Wdm.h. Check these files to see whether additional device types have been defined.
The FILE_DEVICE_DISK specification covers disk partitions and any object that appears as a disk.
Intermediate drivers usually specify device types that represent the underlying device. For example, the system-supplied fault-tolerant disk driver, ftdisk, creates device objects of type FILE_DEVICE_DISK; it does not define new device types for the mirror sets, stripe sets, and volume sets it manages.
FILE_DEVICE_XXX values in the range of 0 through 32767 are reserved for Microsoft. All driver writers must use these system-defined constants for devices belonging to the system-defined device types.
If a type of hardware does not match any of the defined types, specify a value of either FILE_DEVICE_UNKNOWN, or a value within the range of 32768 through 65535.
SetupDiGetClassDevsW function (setupapi.h)
The SetupDiGetClassDevs function returns a handle to a device information set that contains requested device information elements for a local computer.
Syntax
Parameters
A pointer to the GUID for a device setup class or a device interface class. This pointer is optional and can be NULL. For more information about how to set ClassGuid, see the following Remarks section.
A pointer to a NULL-terminated string that specifies:
- An identifier (ID) of a Plug and Play (PnP) enumerator. This ID can either be the value’s globally unique identifier (GUID) or symbolic name. For example, «PCI» can be used to specify the PCI PnP value. Other examples of symbolic names for PnP values include «USB,» «PCMCIA,» and «SCSI».
- A PnP device instance ID. When specifying a PnP device instance ID, DIGCF_DEVICEINTERFACE must be set in the Flags parameter.
This pointer is optional and can be NULL. If an enumeration value is not used to select devices, set Enumerator to NULL
For more information about how to set the Enumerator value, see the following Remarks section.
A handle to the top-level window to be used for a user interface that is associated with installing a device instance in the device information set. This handle is optional and can be NULL.
A variable of type DWORD that specifies control options that filter the device information elements that are added to the device information set. This parameter can be a bitwise OR of zero or more of the following flags. For more information about combining these flags, see the following Remarks section.
DIGCF_ALLCLASSES
Return a list of installed devices for all device setup classes or all device interface classes.
DIGCF_DEVICEINTERFACE
Return devices that support device interfaces for the specified device interface classes. This flag must be set in the Flags parameter if the Enumerator parameter specifies a device instance ID.
DIGCF_DEFAULT
Return only the device that is associated with the system default device interface, if one is set, for the specified device interface classes.
DIGCF_PRESENT
Return only devices that are currently present in a system.
DIGCF_PROFILE
Return only devices that are a part of the current hardware profile.
Return value
If the operation succeeds, SetupDiGetClassDevs returns a handle to a device information set that contains all installed devices that matched the supplied parameters. If the operation fails, the function returns INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
Remarks
The caller of SetupDiGetClassDevs must delete the returned device information set when it is no longer needed by calling SetupDiDestroyDeviceInfoList.
Call SetupDiGetClassDevsEx to retrieve the devices for a class on a remote computer.
Device Setup Class Control Options
Device Interface Class Control Options
Examples
The following are some examples of how to use the SetupDiGetClassDevs function.
Example 1: Build a list of all devices in the system, including devices that are not currently present.
Example 2: Build a list of all devices that are present in the system.
Example 3: Build a list of all devices that are present in the system that are from the network adapter device setup class.
Example 4: Build a list of all devices that are present in the system that have enabled an interface from the storage volume device interface class.
Example 5: Build a list of all devices that are present in the system but do not belong to any known device setup class (Windows Vista and later versions of Windows).
The setupapi.h header defines SetupDiGetClassDevs as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.
CTL_CODE (Windows CE 5.0)
This macro creates a unique system I/O control code (IOCTL).
Parameters
DeviceType
Defines the type of device for the given IOCTL.
This parameter can be no bigger than a WORD value.
The values used by Microsoft are in the range 0-32767; the values 32768-65535 are reserved for use by OEMs and IHVs.
The following device types are defined by the system:
- FILE_DEVICE_BEEP
- FILE_DEVICE_CD_ROM
- FILE_DEVICE_CD_ROM_FILE_SYSTEM
- FILE_DEVICE_CONTROLLER
- FILE_DEVICE_DATALINK
- FILE_DEVICE_DFS
- FILE_DEVICE_DISK
- FILE_DEVICE_DISK_FILE_SYSTEM
- FILE_DEVICE_FILE_SYSTEM
- FILE_DEVICE_INPORT_PORT
- FILE_DEVICE_KEYBOARD
- FILE_DEVICE_MAILSLOT
- FILE_DEVICE_MIDI_IN
- FILE_DEVICE_MIDI_OUT
- FILE_DEVICE_MOUSE
- FILE_DEVICE_MULTI_UNC_PROVIDER
- FILE_DEVICE_NAMED_PIPE
- FILE_DEVICE_NETWORK
- FILE_DEVICE_NETWORK_BROWSER
- FILE_DEVICE_NETWORK_FILE_SYSTEM
- FILE_DEVICE_NULL
- FILE_DEVICE_PARALLEL_PORT
- FILE_DEVICE_PHYSICAL_NETCARD
- FILE_DEVICE_PRINTER
- FILE_DEVICE_SCANNER
- FILE_DEVICE_SERIAL_MOUSE_PORT
- FILE_DEVICE_SERIAL_PORT
- FILE_DEVICE_SCREEN
- FILE_DEVICE_SOUND
- FILE_DEVICE_DEVICE_STREAMS
- FILE_DEVICE_TAPE
- FILE_DEVICE_TAPE_FILE_SYSTEM
- FILE_DEVICE_TRANSPORT
- FILE_DEVICE_UNKNOWN
- FILE_DEVICE_VIDEO
- FILE_DEVICE_VIRTUAL_DISK
- FILE_DEVICE_WAVE_IN
- FILE_DEVICE_WAVE_OUT
- FILE_DEVICE_8042_PORT
- FILE_DEVICE_NETWORK_REDIRECTOR
- FILE_DEVICE_BATTERY
- FILE_DEVICE_BUS_EXTENDER
- FILE_DEVICE_MODEM
- FILE_DEVICE_VDM
- FILE_DEVICE_MASS_STORAGE
- FILE_DEVICE_SMB
- FILE_DEVICE_KS
- FILE_DEVICE_CHANGER
- FILE_DEVICE_SMARTCARD
- FILE_DEVICE_ACPI
- FILE_DEVICE_DVD
- FILE_DEVICE_FULLSCREEN_VIDEO
- FILE_DEVICE_DFS_FILE_SYSTEM
- FILE_DEVICE_DFS_VOLUME
The following device types are specific to Windows CE:
- FILE_DEVICE_HAL
- FILE_DEVICE_CONSOLE
- FILE_DEVICE_PSL
- FILE_DEVICE_SERVICE
Function
Defines an action within the device category.
Function codes 0-2047 are reserved for Microsoft; codes 2048-4095 are reserved for OEMs and IHVs.
A function code can be no larger then 4095.
Method
Defines the method codes for how buffers are passed for I/O and file system controls.
The following values are possible for this parameter:
- METHOD_BUFFERED
- METHOD_IN_DIRECT
- METHOD_OUT_DIRECT
- METHOD_NEITHER
This field is ignored by Windows CE. You should always use the METHOD_BUFFERED value unless compatibility with Windows-based desktop platforms is required using a different Method value.
Access
Defines the access check value for any access.
The following table shows the possible flags for this parameter. The FILE_ACCESS_ANY is generally the correct value.
Flag | Description |
---|---|
FILE_ANY_ACCESS | Request all access. |
FILE_READ_ACCESS | Request read access. Can be used with FILE_WRITE_ACCESS. |
FILE_WRITE_ACCESS | Request write access. Can be used with FILE_READ_ACCESS. |
Return Values
Remarks
The macro can be used for defining IOCTL and FSCTL function control codes. All IOCTLs must be defined this way to ensure that values used by Microsoft, OEMs, and IHVs do not overlap.
The following illustration shows the format of the resulting IOCTL.