enciktangankida Posted October 28, 2011 Posted October 28, 2011 Hai everybody, I'm new here. I need help to solve my problem in vb. I using vb 2008. Actually I creating my application that can solve boot crash for Windows 7. I started code using batch file and convert into .exe format for application solution. The application solution is transfer file like: - ntoskrnl.exe - bootmgr - ntfs.exe - hal.dll Then I execute it using vb form. In real environment everything is going nice. But when I boot that application solution that I already integrate using vb form. The application solution is running as usual but there is no transfer file into directory that I specify. When I boot the application, directory C:\Windows\ that usually we see will change to different path like F:\Windows\ or K:\Windows\ So I scan the directory first and then execute the application solution for each path. Is there any short method to scan directory "Windows" that can detect if it at different path. Can I use %systemroot% and how to use it? Hope someone can help me. TQ. :) This is my code: It execute when I press button. path "x" is refer to opticaldrive. If My.Computer.FileSystem.DirectoryExists("C:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirc.exe") ElseIf My.Computer.FileSystem.DirectoryExists("D:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dird.exe") ElseIf My.Computer.FileSystem.DirectoryExists("E:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dire.exe") ElseIf My.Computer.FileSystem.DirectoryExists("F:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirf.exe") ElseIf My.Computer.FileSystem.DirectoryExists("G:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirg.exe") ElseIf My.Computer.FileSystem.DirectoryExists("H:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirh.exe") ElseIf My.Computer.FileSystem.DirectoryExists("I:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/diri.exe") ElseIf My.Computer.FileSystem.DirectoryExists("J:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirj.exe") ElseIf My.Computer.FileSystem.DirectoryExists("K:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirk.exe") ElseIf My.Computer.FileSystem.DirectoryExists("L:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirl.exe") ElseIf My.Computer.FileSystem.DirectoryExists("M:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirm.exe") ElseIf My.Computer.FileSystem.DirectoryExists("N:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirn.exe") ElseIf My.Computer.FileSystem.DirectoryExists("O:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/diro.exe") ElseIf My.Computer.FileSystem.DirectoryExists("P:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirp.exe") ElseIf My.Computer.FileSystem.DirectoryExists("Q:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirq.exe") ElseIf My.Computer.FileSystem.DirectoryExists("R:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirr.exe") ElseIf My.Computer.FileSystem.DirectoryExists("S:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirs.exe") ElseIf My.Computer.FileSystem.DirectoryExists("T:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirt.exe") ElseIf My.Computer.FileSystem.DirectoryExists("U:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/diru.exe") ElseIf My.Computer.FileSystem.DirectoryExists("V:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirv.exe") ElseIf My.Computer.FileSystem.DirectoryExists("W:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirw.exe") ElseIf My.Computer.FileSystem.DirectoryExists("Y:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/diry.exe") ElseIf My.Computer.FileSystem.DirectoryExists("Z:\Windows\") = True Then Shell("x:/program files/bwef/boot crash solution/dirz.exe") Else MsgBox("No Windows Directory Found") End If Quote
Leaders snarfblam Posted October 28, 2011 Leaders Posted October 28, 2011 The code you have above is sure to run into problems. It's entirely possible for the windows folder to have any arbitrary name, on any drive. If the user installed windows to "F:\LesFenetres", you would never find it that way. Most of the time, you can get the path to special folders (desktop, system, application data, etc.) using the Environment.GetFolderPath function. For some reason, they didn't include the windows directory in the list of special folders, but there is another way we can get special folder paths. You had the right idea with %SYSTEMROOT%. There is also %WINDIR%. They both seems to return the path to the windows folder. I'm not sure if the two variables serve different purposes, but I think you'll be fine with either one. We can get the value for any of these environment variables with the handy Environment.GetEnvironmentVariable function. Dim WinPath As String = Environment.GetEnvironmentVariable("SYSTEMROOT") That should get you what you need. Quote [sIGPIC]e[/sIGPIC]
enciktangankida Posted October 29, 2011 Author Posted October 29, 2011 TQ snarfblam because helping me. :) Can I do the WinPath as the reference to copy my file into directory that found. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.