SetCurrentDirectoryA





API


Imports System.Runtime.InteropServices

Module Module4

    ' Declare the SetCurrentDirectoryA function
    <DllImport("kernel32.dll", CharSet:=CharSet.Ansi, SetLastError:=True)&rt;
    Private Function SetCurrentDirectoryA(lpPathName As String) As Boolean
    End Function

    Sub Main()
        Dim path As String = "C:\games" ' Replace with your actual path

        Dim result As Boolean = SetCurrentDirectoryA(path)

        If result Then
            Console.WriteLine("Directory changed successfully.")
        Else
            Console.WriteLine("Failed to change directory. Error: " & Marshal.GetLastWin32Error())
        End If
    End Sub

End Module


VB.Net


Imports System.IO

Module Module4

    Sub Main()
        Dim path As String = "C:\games" ' Replace with your actual path

        Try
            ' Change the current directory
            Directory.SetCurrentDirectory(path)
            Console.WriteLine("Directory changed successfully to: " & Directory.GetCurrentDirectory())
        Catch ex As Exception
            Console.WriteLine("Failed to change directory. Error: " & ex.Message)
        End Try
    End Sub

End Module