Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:32:06+00:00 2026-05-28T05:32:06+00:00

I want to terminate an application using the full file path via vb.net,so i

  • 0

I want to terminate an application using the full file path via vb.net,so i am using this code snippet

Public Sub forceCopy()
        Try
            'Dim strDatabasePath As String = My.Computer.FileSystem.CombinePath(Application.UserAppDataPath, "LIC.mdf")
            'Dim strdbLogPath As String = My.Computer.FileSystem.CombinePath(Application.UserAppDataPath, "LIC_log.ldf")
            Dim strDatabasePath As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC.mdf")
            Dim strdbLogPath As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC_log.ldf")
            Dim path As String = My.Computer.FileSystem.CombinePath(My.Application.Info.DirectoryPath, "LIC.mdf")
            Dim matchingProcesses = New List(Of Process)

            For Each process As Process In process.GetProcesses()
                For Each m As ProcessModule In process.Modules
                    If String.Compare(m.FileName, path, StringComparison.InvariantCultureIgnoreCase) = 0 Then
                        matchingProcesses.Add(process)
                        Exit For
                    End If
                Next
            Next

            For Each p As Process In matchingProcesses
                p.Kill()
            Next
            My.Computer.FileSystem.CopyFile(strDatabasePath, "c:\backup\LIC.mdf", True)

            My.Computer.FileSystem.CopyFile(strdbLogPath, "c:\backup\LIC_log.ldf", True)

            MessageBox.Show("Backup taken successfully")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

I get an exception “Access Is Denied” .Any idea why?
EDIT: I get the error at this line : For Each m As ProcessModule In process.Modules

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:32:07+00:00Added an answer on May 28, 2026 at 5:32 am

    You’ll need to wrap the If String.Compare(m.FileName, ...) block with Try/Catch. There are several fake and privileged processes whose FileName property you cannot access.

    Killing SQL Server like this is otherwise a Really Bad Idea. Ask nicely with the ServiceController class. You will need UAC elevation to do so.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to terminate an application using the full file path via vb.net, yet
I found this snippet of code here that allows you to log into a
I have created an application using Netbeans 6.9. In the application I want that
I have a .NET/native C++ application. Currently, the C++ code allocates memory on the
I have a .Net program that I want to install on a terminal server.
want to know why String behaves like value type while using ==. String s1
I'm using popen to open a write pipe and send commands to an application.
I am currently using a script to call pkill to terminate my C++ program.
I'm running a command line application from within the perl script(using system()) that sometimes
I have written some simple code, to send en auto generated email, using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.