none
not able to execute batch file though all parameters given correctly RRS feed

  • Question

  • Please help me in executing batch file as it is not working 

    file I want to copy from one location to another location and saved as batch file.

    I want to execute this batch file from both command prompt and  through PowerShell as well. 

    but it is not working in neither of them. Please refer below screenshots

    warning message below:

    With powershell I have done as below, which is also not working. Please help 


    kumar


    • Edited by sns shyam Saturday, November 9, 2019 11:51 AM
    Saturday, November 9, 2019 11:50 AM

Answers

  • Hi sns shyam,

    1) the directory of local Desktop varies according to user who is sign-in.
        Suppose, user account is ABC, the user's directory of Desktop is
        C:\Users\ABC\Desktop\

    2) which is your actual issue?  (a) and (b) are definitely different. 
        a) you cannot run the batch file
        b) the batch file does not work as expected (when it is executed)

        If it is (a), please Change Directory to C:\Users\ABC\Desktop\
        If it is (b), it may cause from user's privilege or may cause from its contents. (I can say nothing, unless its contents are provided.) 

    Regards,

    Ashidacchi -- http://hokusosha.com

    The desktop is not usually in that location.  In PowerShell this is the method:

    # this will always get the current desktop location
    [environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)
    

    Before trying to figure out how to advise users it is necessary to learn basic Windows technology.  What is true foro the home user will not work for a corporate installation of Windows as most current deployments change the location of most standard folders.  The above works for both home (workgroup) and enterprise installations.

    On all of my home systems the desktop and other folders are here:

    C:\Users\myaccount\OneDrive\Desktop

    On my domain system the folders are on a network share and have no drive letter.

    Learning Windows technology is a prerequisite for understanding the implications of users questions and issues.  The last question indicates a non-standard installation and may indicate a system corruption or misconfiguration.

    Don't use guesses to help people as that will only cause more issues.


    \_(ツ)_/

    • Marked as answer by jrvModerator Monday, November 11, 2019 9:54 PM
    Sunday, November 10, 2019 7:05 AM
    Moderator

All replies

  • Powershell doesn't run programs from the default directory. Change to the correct directory and prefix the name of the file with ".\", or use the full path name (e.g., "c:\mydirectory\test2.bat").

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Saturday, November 9, 2019 3:41 PM
  • With powershell I have done as below, 


    There is no reason to run Powershell just to run cmd.exe to copy a file. Just use the Copy-item command.

    PS C:\WINDOWS\system32> get-help Copy-Item
    
    
    NAME
        Copy-Item
        
    SYNOPSIS
        Copies an item from one location to another.
        
        
    SYNTAX
        Copy-Item [[-Destination] <String>] [-Confirm] [-Container] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] [-Force] 
        [-FromSession <PSSession>] [-Include <String[]>] -LiteralPath <String[]> [-PassThru] [-Recurse] [-ToSession <PSSession>] [-UseTransaction] [-WhatIf] 
        [<CommonParameters>]
        
        Copy-Item [-Path] <String[]> [[-Destination] <String>] [-Confirm] [-Container] [-Credential <PSCredential>] [-Exclude <String[]>] [-Filter <String>] 
        [-Force] [-FromSession <PSSession>] [-Include <String[]>] [-PassThru] [-Recurse] [-ToSession <PSSession>] [-UseTransaction] [-WhatIf] 
        [<CommonParameters>]
        
        
    DESCRIPTION
        The Copy-Item cmdlet copies an item from one location to another location in the same namespace. For instance, it can copy a file to a folder, but it 
        cannot copy a file to a certificate drive.
    If you did not know about the PATH as Marco pointed out, then I would suggest that you take some courses in Windows fundamentals.

    Saturday, November 9, 2019 3:53 PM
  • Hi sns shyam,

    It would work,  if you save it in "C:\WINODOWS\system32".

    Where do you have a file "test2.bat"?
    If you want to execute it in CMD, please Change Directry where the "test2.bat" is located.

    Regards,


    Ashidacchi -- http://hokusosha.com

    Sunday, November 10, 2019 2:04 AM
  • Hi Ashidacchi,

    it is not changing the directory. why it is not changing the directory? and I want to run it with particular account not with admin account. Please help 


    kumar

    Sunday, November 10, 2019 4:57 AM
  • Hi sns shyam,

    From the old days, Windows (MS-DOS, also) has Environment Variables where paths are described for search-path.

    If your batch file "test2.bat" is in a path which is described in Environment Variables, you can execute it wherever the current directory is.
    If it is saved in "C:\WINDOWS\system32", you can execute it.

    That is why I asked its location.
     
    According to your picture, you need to type like this (in Command Prompt).
    E: [Return]
    CD SP_SutoInstaller\AutoSPInstaller [Return]
    # I guess you typo: AutoInstaller instead of SutoInstaller

    Regards,

    Ashidacchi -- http://hokusosha.com



    • Edited by Ashidacchi Sunday, November 10, 2019 5:23 AM typo
    Sunday, November 10, 2019 5:18 AM
  • Hi Ashidaachi,

    Thank you for the response 

    test02 file is there on local desktop. so cant we change it desktop location directory in cmd? 

    Pl will try putting file in system32 and let you know..

    command you have given in the end for auto installer batch file it is not working.. can you please tell me what exactly I need to do..right now I am in adminstartor account..

     I want to run command prompt with service account, please let me know how to use run as command in the CMD...


    kumar


    • Edited by sns shyam Sunday, November 10, 2019 5:42 AM
    Sunday, November 10, 2019 5:41 AM
  • Hi sns shyam,

    1) the directory of local Desktop varies according to user who is sign-in.
        Suppose, user account is ABC, the user's directory of Desktop is
        C:\Users\ABC\Desktop\

    2) which is your actual issue?  (a) and (b) are definitely different. 
        a) you cannot run the batch file
        b) the batch file does not work as expected (when it is executed)

        If it is (a), please Change Directory to C:\Users\ABC\Desktop\
        If it is (b), it may cause from user's privilege or may cause from its contents. (I can say nothing, unless its contents are provided.) 

    Regards,

    Ashidacchi -- http://hokusosha.com

    Sunday, November 10, 2019 6:51 AM
  • DO NOT put files in the Windows folders. They are protected and use is disallowed by Microsoft,  Updates and upgrades will often clobber your files. Use the current folder, the full path or place the file in a folder in the path. First learn basic Windows before trying to make changes to they system or trying to understand how things work.

    Your question is not really a scripting question.  It is a new Windows user question and should be asked here: http://answers.microsof.com.

    This forum is for trained techs and not for home or non tech users so you will likely not be able to get the help you need.


    \_(ツ)_/

    Sunday, November 10, 2019 6:57 AM
    Moderator
  • Hi sns shyam,

    1) the directory of local Desktop varies according to user who is sign-in.
        Suppose, user account is ABC, the user's directory of Desktop is
        C:\Users\ABC\Desktop\

    2) which is your actual issue?  (a) and (b) are definitely different. 
        a) you cannot run the batch file
        b) the batch file does not work as expected (when it is executed)

        If it is (a), please Change Directory to C:\Users\ABC\Desktop\
        If it is (b), it may cause from user's privilege or may cause from its contents. (I can say nothing, unless its contents are provided.) 

    Regards,

    Ashidacchi -- http://hokusosha.com

    The desktop is not usually in that location.  In PowerShell this is the method:

    # this will always get the current desktop location
    [environment]::GetFolderPath([System.Environment+SpecialFolder]::Desktop)
    

    Before trying to figure out how to advise users it is necessary to learn basic Windows technology.  What is true foro the home user will not work for a corporate installation of Windows as most current deployments change the location of most standard folders.  The above works for both home (workgroup) and enterprise installations.

    On all of my home systems the desktop and other folders are here:

    C:\Users\myaccount\OneDrive\Desktop

    On my domain system the folders are on a network share and have no drive letter.

    Learning Windows technology is a prerequisite for understanding the implications of users questions and issues.  The last question indicates a non-standard installation and may indicate a system corruption or misconfiguration.

    Don't use guesses to help people as that will only cause more issues.


    \_(ツ)_/

    • Marked as answer by jrvModerator Monday, November 11, 2019 9:54 PM
    Sunday, November 10, 2019 7:05 AM
    Moderator
  • @jrv,
       I don't want to discuss this issue with a very knowledgeable.

    @kumar,
      Have you resolved the issue?
      I only hope it.

    Regards,  

    Ashidacchi -- http://hokusosha.com

    Monday, November 11, 2019 9:50 PM
  • @jrv,
       I don't want to discuss this issue with a very knowledgeable.

    @kumar,
      Have you resolved the issue?
      I only hope it.

    Regards,  

    Ashidacchi -- http://hokusosha.com

    Your post doesn't make much sense in English.


    \_(ツ)_/

    Monday, November 11, 2019 9:54 PM
    Moderator