Results 1 to 11 of 11

Thread: How can I write a Batch file for setting paths & registering a .NET DLL?

  1. #1

    Thread Starter
    New Member kennasoft's Avatar
    Join Date
    Jun 2007
    Location
    *****, Nigeria
    Posts
    8

    How can I write a Batch file for setting paths & registering a .NET DLL?

    Hi everybody, I love what u guys are doing here, keep it up people!
    Errr... I'm new to .NET development though i'm a veteran developer in Java and PHP. I recently wrote a VB.NET DLL for a friend who does VBA apps with MS ACCESS, and he needs to use it on multiple systems.

    Those who have created interop DLLs know the hell u have to go through to register & set it up to work (all the GAC, SN and REGASM stuff). I don't want my friend to go through all this trouble each time he wants to run his app on a new System and refernce my DLL.

    So, here comes my problem. I know a batch can file can solve this problem, but I've never written a batch file before. I need help from anyone who can write a batch file to set the path of the EXECs [gacutil.exe, regasm.exe], and then run the regasm.exe tool with the '/tld:' switch to create the .tld file & also run gacutil.exe to register it in the GAC. I want him to copy the .DLL, .BAT and .SNK files to Windows\System32 folder then just click the batch file to do all the registering.

    Somebody please help!

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    This is a basic way to register a .dll with the help of batch file. Type this in a text file and save it as updatebatchfiles.bat

    Regsvr32.exe c:\windows\system32\myfile1.Dll
    Regsvr32.exe c:\windows\system32\myfile2.Dll
    Regsvr32.exe c:\windows\system32\myfile3.Dll

    If you search this forum you will find plenty of examples on batch files.

    Hope this puts you in the right direction....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    New Member kennasoft's Avatar
    Join Date
    Jun 2007
    Location
    *****, Nigeria
    Posts
    8

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    Hey koolsid, thanks for ur help, but that would only work for COM components written in VB6 or versions before .NET; trust me, i know i went through some DLL hell trying to use RegSvr32 to register it before.

    My actual problem here is not how to register the DLL, but how to create a batch file to do that with one click.

    Thanks again!

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    why not use a script?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    Moved to VB.NET

  6. #6
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    Try this batch file:

    %windir%\Microsoft.NET\Framework\v2.0.50727\regasm.exe "VB.net dll path"

    If you keep the .bat file and dlls in the same directory then u need to just specify VB.net dll name instead off full path.

  7. #7

    Thread Starter
    New Member kennasoft's Avatar
    Join Date
    Jun 2007
    Location
    *****, Nigeria
    Posts
    8

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    Hey, Deepak thanks, that helped a lot, but i wonder if there's an environment variable that .NET sets on installation that holds the full or relative path of the current .NET framework installation like the '%windir%' bit you used.

    I'd like it to be a one-time script that works even if there's a different version of .NET.

    Thank you so much

  8. #8
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    Unfortunately Microsoft has not provided any environment variable which holds .NET Framework path. Better you create different batch files for each version.

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    Why aren't you creating a deployment application with a merge module?

  10. #10

    Thread Starter
    New Member kennasoft's Avatar
    Join Date
    Jun 2007
    Location
    *****, Nigeria
    Posts
    8

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    Quote Originally Posted by Deepak Sakpal
    Unfortunately Microsoft has not provided any environment variable which holds .NET Framework path. Better you create different batch files for each version.
    Hey thanx again Deepak; i guess i'll have to resort to multiple batch files then.

  11. #11

    Thread Starter
    New Member kennasoft's Avatar
    Join Date
    Jun 2007
    Location
    *****, Nigeria
    Posts
    8

    Re: How can I write a Batch file for setting paths & registering a .NET DLL?

    mendhak, what is a merge module, & how do i create one?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width