Wrox Programmer Forums
|
BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8
This is the forum to discuss the Wrox book Professional C# 2008 by Christian Nagel, Bill Evjen, Jay Glynn, Morgan Skinner, Karli Watson; ISBN: 9780470191378
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2009, 03:16 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default Create illegal folders

Hello
in Visual Basic 6.0 by mkdir function we could create illegal folders like this:
mkdir "\\.\C:\CON"
I used this method to create a program that protect usb drive against some viruses
mkdir "I:\AUTORUN.INF"
mkdir "\\.\I:\AUTORUN.INF\CON"
then autorun.inf folder can't be removed

I'm trying to write this code using C#, but some available functions like Directory.CreateFolder("\\.\I:\CON"); does not work and throws an exception
how can i get help?

Last edited by irProject; December 7th, 2009 at 03:18 AM..
 
Old December 13th, 2009, 06:39 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

as you know mkdir uses a function of system to create new directory. so we can call an api function to do this. but what is the name of specific api function?
 
Old December 13th, 2009, 06:52 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

api function name is CreateDirectory
but i will test to know does it work? ( to make illegal folder )
 
Old December 13th, 2009, 07:27 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Smile THANKS

I found the answer

Code:
class Program
{
	static void Main(string[] args)
	{
		SECURITY_ATTRIBUTES lpSA = new SECURITY_ATTRIBUTES();
		lpSA.nLength = 24;
		if (CreateDirectory(@"\\.\c:\con", ref lpSA) != 0)
		{
			Console.WriteLine("OK");
		}
		else
			Console.WriteLine("NO");
		Console.ReadLine();
	}

	struct SECURITY_ATTRIBUTES
	{
		public long nLength;
		public long lpSecurityDescriptor;
		public long bInheritHandle;
	}

	[DllImport("kernel32.dll")]
	private static extern long CreateDirectory(string lpPathName, ref SECURITY_ATTRIBUTES lpSecurityAttributes);
}
thanks to all your answers!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Illegal Character in Flat file Mehdi6002 BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 2 July 3rd, 2009 12:10 PM
Illegal Assignment Broodmdh Classic ASP Basics 2 August 22nd, 2008 06:21 AM
ERROR: Illegal characters in path owen_xgy .NET Framework 2.0 8 April 2nd, 2008 10:21 AM
Illegal assignment: 'adCmdText' jackiew ASP.NET 1.0 and 1.1 Basics 1 August 23rd, 2007 09:29 AM
Illegal key size rnmisrahi BOOK: Beginning Cryptography with Java 3 January 8th, 2007 09:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.